Execution of Blocks-Static,Init,Constructor - DV's Coding Corner
 
public class super1 {
static_init_constuctr() { System.out.println("super1_construct"); } //5
static { System.out.println("super1_static"); }  //1
{ System.out.println("super1_init"); } //4


public static void main(String args[]) {
sub2 ref =new sub2();
System.out.println("The End"); //10
}
}

class sub1 extends super1{
B(){ System.out.println("sub1_construct"); } //7
static{ System.out.println("sub1_static"); } //2
{ System.out.println("sub1_init"); } //6
}

class sub2 extends sub1{
C(){ System.out.println("sub2_construct"); } //9
static{ System.out.println("sub2_static"); } //3
{ System.out.println("sub2_init"); } //8
}

Output:
super1_static
sub1_static
sub2_static
super1_init
super1_construct
sub1_init
sub1_construct
sub2_init
sub2_construct
The End




Leave a Reply.