private satic 注意与应用

  1. public class Dog  
  2. {  
  3.        private static int count;     //static member  
  4.    
  5.        public Dog()  
  6.        {       count++;  
  7.        }  
  8.         
  9.        public static void main(String a[])  
  10.        {   Dog d=new Dog();  
  11.            Dog dd=new Dog();  
  12.            new Dog();  
  13.            Dog.display();       
  14.         }  
  15. private static void display()  
  16. {  
  17.       System.out.println(count);  
  18. }  
  19.  
  20. 输出结果为:为3;
  21. 应用:单例模式:http://calmness.iteye.com/blog/60179

posted on 2012-07-01 17:00  elegantyuanjian  阅读(114)  评论(0)    收藏  举报

导航