ITeye博客

Java 执行顺序

shenghw · 2012-12-22 12:42 · java基础 · 编程语言 · Markdown


class T {
	T() {
		System.out.println("super construct");
	}

	{
		System.out.println("super no static ");
	}
	static {
		System.out.println("super  static ");
	}
}

public class E extends T {
	E() {
		System.out.println("construct");
	}

	static int a = 0;

	{
		System.out.println("no static c");
	}
	static {
		System.out.println("static ");
	}

	public static void main(String args[]) {
		System.out.println("后于静态代码段执行");
		new E();

	}
}


执行结果如下:

super static static 后于静态代码段执行 super no static super construct no static c construct

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。