aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes initialization sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "initialization sequence" Watch "initialization sequence" New topic
Author

initialization sequence

Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Dear All,
Hey,
What is the correct sequence of execution of Super Class - Sub Class:

Super class's Static initializer//1
Super class's instance intializer//2
Super Class's Constructor//3
SUB class's instance intializer//4
SUB class's Static intializer//5
SUB class's Constructor//6

I have a code which gives the above above sequence.
Why is the sub class's static initializer (5) initialized after the sub class's instance initializer. Is it because the call to the constructor of the sub class, gives the call super(), which when returned, goes back to the constructor of the sub class.
Why is this happening???
Please Clarify.
The code for the above result is followed.
Thanks a lot!!
Bye,
Tualha Khan

*****************************************
class tt1
{
{
System.out.println("In Super class's instance intializer");
}
static
{
System.out.println("In Super class's Static initializer");
}
tt1()
{
System.out.println("In Super Class's Constructor");
}
}
class tt2 extends tt1
{
{
System.out.println("In SUB class's instance intializer");
}
{
System.out.println("In SUB class's Static intializer");
}
tt2()
{
System.out.println("In SUB class's Constructor");
}
public static void main(String args[])
{
new tt2();
}
}
***************************************

SCJP2, BEA WLS 6.0, DB2 UDB 7.1
Vijay pillai
Ranch Hand

Joined: Jan 10, 2001
Posts: 45
hi,
the order of initialisation is always the super class static initializer,then the subclass static initializer,the instance ini of the super then is the call to the constructor of the super made.
followed by the call to the ini if any of the sub class.
the code u have presented in sub doesn't have a static ini instead its the 2nd instance ini printing.
thanks
Vijay Pillai
Kedar Jog
Greenhorn

Joined: Feb 06, 2001
Posts: 5
U are missing static keyword in the init sequence in the child class
-Kedar
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Such a silly mistake, my future boss will fire me anything!!
Bye,
Tualha Khan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: initialization sequence
 
Similar Threads
A simple Q but still have doubt
A constructor question
Inheritance again
constructor giving headache
Thread Q