类,父类初始化顺序

package cn.galc.test;

class Creature
{
    {
        System.out.println("Creature 0");
    }
    
    static
    {
        System.out.println("Static Creature 0");
    }
    public Creature()
    {
        System.out.println("Constructor Creature 0");
    }
    public Creature(int i)
    {
        System.out.println("Constructor Creature 0" + i);
    }
}

class Dog extends Creature
{
    {
        System.out.println("Dog 0");
    }
    
    static
    {
        System.out.println("Static Dog 0");
    }
    public Dog()
    {
        System.out.println("Constructor Dog 0");
    }
    public Dog(int i)
    {
        System.out.println("Constructor Dog 0" + i);
    }
}

public class Test {
    public static void main(String args[]) {     
        Dog dog = new Dog();         
    }
}

 

Static Creature 0
Static Dog 0
Creature 0
Constructor Creature 0
Dog 0
Constructor Dog 0

你可能感兴趣的:(类初始化)