没错,谢谢!- class Demo
- {
- public static void main(String[] args) throws Exception
- {
- Singleton instance = Singleton.getInstance();
- }
- }
- class Singleton{
- private static Singleton instance = new Singleton();
- private Singleton(){System.out.println("单例模式-饿汉式");}
- public static Singleton getInstance(){
- return instance;
- }
- }
复制代码 |