JAVA类的初始化执行顺序探讨

来源:互联网 发布:淘宝如何搜高仿手表 编辑:程序博客网 时间:2024/05/22 11:12
package hello;public class Test {{System.out.println("Parent无参构造方法");}static {System.out.println("Parent静态方法");}public static void main(String args[]) {Child c1 = new Child("哈哈哈1");System.out.println("***********");Child c2 = new Child();}}class Parent {public Parent() {System.out.println("Parent无参构造方法");}public Parent(String s) {System.out.println("Parent无参构造方法  " + s);}{System.out.println("Parent无参构造方法");}static {System.out.println("Parent静态方法");}}class Child extends Parent {public Child() {System.out.println("Child无参构造方法");}public Child(String s) {super("调用Parent带参数方法");System.out.println("Child无参构造方法  " + s);}{System.out.println("Child无参构造方法");}static {System.out.println("Child静态方法");}}


先不运行自己看下结果,然后再运行下。后续我会详解运行过程。

0 0
原创粉丝点击