Can you elaborate a little more on the question? All object creation is done through constructors. If no constructor is specified, the compiler will supply a default empty constructor that basically does nothing. If you wish to provide info that initializes some values in the object when it's created, you provide a constructor for those parameters and initialize those values in that constructor.
Ezzaral
Posting Genius
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Do you think that user of your application will be interested in reading your code and seting all variables by him self? Or do you think all variables are always initialized?
peter_budo
Code tags enforcer
15,432 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
can you tell me why we create constructor?
We use/call constructors to create instances of objects. In that way we can call the methods of the class.
We define different constructors for different functionality based on their arguments.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
WHAT IS CONSTRUCTOR
--------------------
1. A constructor creates an Object of the class and by initializing all the instance variables and creating a place in memory to hold the Object.
2. It is called using "new "
Why we Need Constructor
-----------------------
1. For simple programs , initializing can be done by user. that will not be a prob.
But consider a case where there is 20 or more instance member.
If the programmer make the user to initialize all , that will be very bad way of programming.
new_programmer
Junior Poster in Training
53 posts since Jul 2010
Reputation Points: 10
Solved Threads: 6
@Lourdupinto to latte with very weak explanation.
Thread closed before another time traveller try to hit
peter_budo
Code tags enforcer
15,432 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901