class nonStatic1 {
nonStatic2 n2 = new nonStatic2();
nonStatic1() {
this.print();
}
void print() {
System.out.println("insidenonStatic1");
}
}
class nonStatic2 {
nonStatic2() {
this.print();
}
void print() {
System.out.println("insidenonStatic2");
}
}
class nonStatic3 {
nonStatic1 n1 = new nonStatic1();
nonStatic3() {
this.print();
}
void print() {
System.out.println("insidenonStatic3");
}
}
public class NonStaticInitializationTest {
nonStatic2 n2 = new nonStatic2(); // <-- Never initialized!!
public static void main(String args[]) {
System.out.println("initialising n3 through main");
nonStatic3 n3 = new nonStatic3();
}
}
元芳怎么了
相关分类