Performing a static relationship between the code blocks and between sub-class parent class, static methods, non-static block constructor

father:

public  class StaticShunXu {
     public  static  void Test () { 
        System.out.println ( "parent - Static Method"); // in the same manner covering subclass 
    }
     static { 
        System.out.println ( "parent - Static code block " ); 
    } 

    public StaticShunXu () { 
        System.out.println ( " parent - constructor " ); 
    } 


    { 
        System.out.println ( " parent - block non-static " ); 
    } 

}

Subclass:

public  class StaticShunXuB the extends StaticShunXu {
     public  static  void Test () { 
        System.out.println ( "subclass - Static Method" ); 
    } 
    static { 
        System.out.println ( "subclass - static code block" ); 
    } 

    { 
        System.out.println ( "subclass - non-static block" ); 
    } 

    public StaticShunXuB () { 
        System.out.println ( "subclass - constructor" ); 
    } 
}

Results of the:

Parent - static block of code 
subclass - static code block 
parent class - non-static block 
parent - Constructor 
subclass - non-static block 
subclass - Constructor 
subclass - Static Method

 

Guess you like

Origin www.cnblogs.com/heqiyoujing/p/11125819.html