Hi Hank...
"Constructor provides information about, and access to, a single constructor for a class." Java Definition...
When you have a class say MyClass.java
And you want to create an instance of it..
MyClass thisClass = new MyClass();
What that does now is that it calls the constructor of that class... Automatically...
For instance here is MyClass class....
class MyClass {
// Make a private String for this class only
private String theStr = "";
// First constructor only takes no arguments
public MyClass() {
this.theStr = "No Arguments";
}
// Lets make another constructor that takes a String as a argument
public MyClass(String str) {
this.theStr = str;
}
// Now the method....
public void myMethod() {
// Which would print the classes String...
System.out.println(this.theStr);
}
}
And to call that we just do this.. from any other class or from main
// Create the object of MyClass *NOTE no parameter given....
MyClass onlyClass = new MyClass();
onlyClass.myMethod();
MyClass nextClass = new MyClass("OMG THIS IS SO COOL");
nextClass.myMethod();
So what will this print? So upon instantiating a class, the constructor of that class is called automatically....
the result of the above would be...
No Arguments
OMG THIS IS SO COOL
I hope that helped..
A Method is methods you call after creation of a class was set..
> Break it down once more Chief :P
Read a frickin' tutorial.
[url=http://java.sun.com/docs/books/tutorial/]Sun's basic Java tutorial[/url]
[url=http://java.sun.com/learning/new2java/index.html]Sun's New To Java Center[/url]. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[url=http://javaalmanac.com]http://javaalmanac.com[/url]. A couple dozen code examples that supplement [url=http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance]The Java Developers Almanac[/url].
[url=http://www.jguru.com]jGuru[/url]. A general Java resource site. Includes FAQs, forums, courses, more.
[url=http://www.javaranch.com]JavaRanch[/url]. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [url=http://mindview.net/Books/DownloadSites]Thinking in Java[/url] (Available online.)
Joshua Bloch's [url=http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh]Effective Java[/url]
Bert Bates and Kathy Sierra's [url=http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance]Head First Java[/url].
James Gosling's [url=http://www.bookpool.com/sm/0321349806]The Java Programming Language[/url]. Gosling is
the creator of Java. It doesn't get much more authoratative than this.
> Thank you very much! I now understand, thanks to
> everyone apart from Mr. jverd
jverd gave you valuable resources to review. Your only beef could be the tone in which it was given, but you very much warrant such a tone, being the research-challenged spoon-feed-me nincompoop that you appear to be.