Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Contructor vs. method

Status
Not open for further replies.

BradIngram

Programmer
Joined
Nov 22, 2002
Messages
2
Location
CA
What is the difference between a constructor and a method?
 
Well Brad, I don't know if you're being serious or not.

But in case you are, a constructor is actually a specific kind of method that is automatically invoked when an object is created. It usually contains any initialization code that the object needs. There is a lot more to it, but that's the basic gist (sp?).

ed
[afro]
 
Well i was being serious i just phrased it very ignorantly...
I'm just an aspiring programmer right now and going to university to learn.
I should have taken a few seconds to phrase exactly what i wanted to know..

Here i go: Is there any other specific purpose of a constructor besides the initilization code of the created object?
 
As Supermole as said, constructor has no other purpose than initializing the object. I should add that you can define as many constructors as you want as soon as they have differents parameters I explain :
Code:
toto = new myClass();
will call
Code:
public myClass()
constructor while
Code:
toto = new myClass("firstParm");
will call
Code:
public myClass(String parm)
constructor. So many constructors can be usefull to instanciate your class many ways. Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top