Java Constructors Initialization.
Java Constructors Initialization
How constructors are chained together and when instance variable initialization occurs can be devided in the following alternative cases:-
If the first statement in a constructor is an ordinary
statement i.e., not a call to this() or super().
- Java inserts an implicit call to super() to invoke the default constructor of the superclass.
- Java initializes the instance variables of the current class.
- Execute the statements of the current constructor.
-
If the first statement in a constructor is a call
to a superclass constructor via super().
- Java invokes the selected superclass constructor.
- Java initializes the instance variables of the current class.
- Execute the statements of the current constructor.
-
If the first statement in a constructor
is a call to an overloaded constructor via this().
- Java invokes the selected constructor.
- Execute the statements of the current constructor (the initialization of instance variables has already occurred in the called constructor).
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.