编写一个Singleton程序(单例)

时间:2022-12-31 20:01:24
public class Test {
private static Test test = new Test();
private Test(){}//构造方法私有化
private static Test test(){
return test;
}
public void run(){
System.out.println("run");
}

public static void main(String[] args) {
Test s = Test.test();
s.run();
}
}