java初始化顺序

class duyin {
    static {
        System.out.println("parnet static");
    }

    String strParent = getParentInstances();

    public String getParentInstances() {
        System.out.println("parent Instance");
        return "abc";
    }

    public duyin() {
        System.out.println("parent created");
    }
}

public class TT extends duyin {
    static {
        System.out.println("child static");
    }

    String strChild = getChildInstances();

    public String getChildInstances() {
        System.out.println("child Instance");
        return "abcd";
    }

    public TT() {
        System.out.println("child created");
    }

    public static void main(String[] args) {
        System.out.println("hello world");
        duyin du = new duyin();
        TT te = new TT();

    }
}

你可能感兴趣的:(java,Ruby)