Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor" Watch "Constructor" New topic
Author

Constructor

Sherman Hung
Greenhorn

Joined: Dec 15, 2001
Posts: 17
In my reading, there are lots of references to CONSTRUCTOR. What exactly does the word constructor mean? Sometimes, it means a class, a object. . .
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Basically, a constructor is used to construct a new object, i.e. an new instance of a class.
This link will help you understand what a constructor is:
JLS 8.8 Constructor Declarations
HIH


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Pradeepa Battina
Greenhorn

Joined: Jan 08, 2002
Posts: 3
1.A constructor is a method with the same name as that of the class.
2.It doesn't have any return type.
3.It is generally used for initialization of instance variables.
This are the basic things about a constructor.
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Check out the Java tuotrial at
http://java.sun.com/docs/books/tutorial/java/javaOO/constructors.html
You can also search the tutorial site for the word Constructor.
HTH
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Just adding my $0.02 to what Pradeepa said:
A constructor IS NOT a method. It looks like one (without the return type, though). The difference lies in the way constructor are invoked, a constructor is NEVER invoked the same way as a method. Constructors are invoked by class instance creation expressions (JLS 15.9, Dave Vick's article in the January Newsletter). Constructors are NEVER invoked by method invocation expressions (JLS 15.12 + article in the February Newsletter).
HIH
Sorry for being picky...
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Just to make things muddier . . . We were discussing the same topic in Beginner.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor