单例

 1 public class Singleton{
 2 
 3     private Singleton s ;
 4     
 5     private Singleton() {};
 6     
 7     public static Singleton getInstance{
 8         if(s==null){
 9             
10         s = new Singleton();    
11         }
12         return s;
13     }
14     
15 }
16 
17 public class Singleton {
18     
19     private Singleton s = new Singleton();
20     
21     private Singleton(){};
22     
23     public static Singleton getInstance(){
24         
25         return s;
26     }    
27 
28 }

 

posted @ 2015-04-29 21:46  MyCloud  阅读(131)  评论(0编辑  收藏  举报