Full object instantiation is complete when the constructor runs. The "this" object can be used to instantiate variables like so... this.variable = value
So in my opinion, only when the contructor exits is your object ready for use, just in case you want some variables that it has to be instantiated in some way.
You wont get this as a question in the exam by the way.
Steps of constructing an object: 1) The Java virtual machine allocates enough unused memory in the heap that can be used to hold the object; 2) The Java virtual machine insures proper initialization of objects. Set fields to default initial values (0, false, null) 3) Call the constructor for the object (but don't execute the body of the constructor yet) 4) Invoke the constructor of the superclass 5) Initialize fields using initializers and initialization blocks 6) Execute the body of the constructor
if you new an object,after initialization,the object's parameter will endow the variable,the last is constructor,it will bestrow the variable,and finish creating the object!so i think object is the first,constructor is going with it,but i think constructor is finish first!that's just my own opinion.so i don't know if i say that is right!
You can consider the constructor as a process to create an object. and object as the result of constructore. If the constructor fails there will be no object. an object creates itself... through constructor.
The hen creates the egg of itself and come out the egg... do you understand....
if you think you can you r right<br />if you think you can not you r double right
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
posted
0
Thanks kwan and balaji! I would conclude, "Constructor call and execution... is part of the object creation."
I would like to konw few more things... 1. An abstract class can not be instantiated or its object can not be created. 2. However inheriting an abstract class and instantiatng the same(child-class), calls the (parent)abstract-class's constructor.
"Constructor Summary: Does nothing, because this is an abstract class."
When an abstract class can not be instantiated, and the only to make use of class is through inheritance, then do we really need a constructor for such a class?
"Constructor Summary: Does nothing, because this is an abstract class."
When an abstract class can not be instantiated, and the only to make use of class is through inheritance, then do we really need a constructor for such a class?
Sure, supose you have an abstract class that contains some objects, in the constructor you could change the states of those objects, specially if you have a constructor that requires some arguments.
SCWCD<br />SCJP<br /> <br />Pedro Henrique Lobato Sena
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.