您的位置:首页 > 编程语言 > Java开发

java中对象方法初始化顺序

2012-03-12 20:24 330 查看
先初始化静态变量,且只需初始化一次。

public class Test {

	public static void main(String[] args) {
		A a1 = new A();
		B b2 = new B(1);
		new A();
	}
}
class A {

	public A() {
		super();
		System.out.println("A 的构造方法...");
	}
	public static B b = new B(0);
	
}

class B {
	public B(int i) {
		super();
		System.out.println("B 的构造方法..." + i);
	}
}
B 的构造方法...0

A 的构造方法...

B 的构造方法...1

A 的构造方法...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: