object creation in java behind scenes (java object instantiation) -
i understand there 3 parts object creation:
- declaration
- instantiation
- initialization
classa{} classb extends classa{} classa obj = new classb(1,1);
instantiation
it has create object using new operator , object must have fields related classb
(initialized default values step give call default constructor?) instantiation mean step initialization using java's default constructor?
initialization
this object passed down hierarchy giving calls various constructor in way initialized (which comes under initialization) , final obj created 'classb(1,1)` constructor whith required initializations
but how object mentioned in instantiation step being created available fields?
please point out if said wrong
if class has no constructor default constructor implicitly defined. constructors have method name <init>
in stacktrace.
a constructor call following:
- the object created, fields nulled: 0, 0.0, null, ...
- the super constructor called, possibly implicit if not present in code.
- all initialized fields (
a = ...;
) initialized doing assignments. - the rest of constructor executed.
Comments
Post a Comment