package org.classdemo;
class Single{
private static Single instance = new Single();
private Single(){
}
public static Single getInstance(){
return instance;
}
public void print(){
System.out.println("Hello World!!");
}
}
public class SingleDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Single s = null;
s = s.getInstance();
s.print();
}
}
JAVA 单例设计
最新推荐文章于 2024-07-24 15:19:30 发布