This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
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
posted
0
U are missing static keyword in the init sequence in the child class -Kedar
Tualha Khan
Ranch Hand
Joined: Nov 22, 2000
Posts: 287
posted
0
Such a silly mistake, my future boss will fire me anything!! Bye, Tualha Khan
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.