源码:
package reborn;
class Mug {
Mug(int marker) {
System.out.println("Mug(" + marker + ")");
}
void f(int marker) {
System.out.println("f(" + marker + ")");
}
}
public class hello {
Mug c1;
Mug c2;
{
c1 = new Mug(1);
c2 = new Mug(2);
System.out.println("c1 & c2 initialized");
}
hello() {
System.out.println("Mugs()");
}
public static void main(String[] args) {
System.out.println("Inside main()");
hello x = new hello();
}
}
输出:
Inside main()
Mug(1)//先进行非静态实例初始化
Mug(2)
c1 & c2 initialized
Mugs()