package org.cc.demo.JVMTest;
class Test{
private static Test test=new Test();
private static int i=5;
private static int j=4;
public Test(){
System.out.println(i);
System.out.println(j);
}
public static Test getInstance(){
return test;
}
}
public class JVMDemo01 {
public static void main(String[] args) {
Test t=Test.getInstance();
}
}
这是第二段:
Java code
package org.cc.demo.JVMTest;
class Test{
private static Test test=new Test();
private int i=5;
private int j=4;
public Test(){
System.out.println(i);
System.out.println(j);
}
public static Test getInstance(){
return test;
}
}
public class JVMDemo01 {
public static void main(String[] args) {
Test t=Test.getInstance();
}
}
另外,你还可以试试在main里面只留下: Class.forName("org.cc.demo.JVMTest.Test");
------解决方案-------------------- new Test()时赋值滴
------解决方案-------------------- new Test()时,调用构造器之前
------解决方案--------------------