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().
    1. Java inserts an implicit call to super() to invoke the default constructor of the superclass.
    2. Java initializes the instance variables of the current class.
    3. Execute the statements of the current constructor.
  • If the first statement in a constructor is a call to a superclass constructor via super().
    1. Java invokes the selected superclass constructor.
    2. Java initializes the instance variables of the current class.
    3. Execute the statements of the current constructor.
  • If the first statement in a constructor is a call to an overloaded constructor via this().
    1. Java invokes the selected constructor.
    2. 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.