java技术博客

jsp博客
数据加载中……
记录类被实例化的次数
/*01*/public class classNumberDemo 
/*02*/{
/*03*/      public static int objNum=0;
/*04*/      public classNumberDemo()
/*05*/      {
/*06*/          classNumberDemo.objNum++;
/*07*/      }

/*08*/      public void show()
/*09*/      {
/*10*/          System.out.println("the No."+classNumberDemo.objNum);
/*11*/      }

/*12*/      
/*13*/        public static void main(String args[])
/*14*/        {
/*15*/             classNumberDemo p=null;
/*16*/             p=new classNumberDemo();
/*17*/             p.show();
/*18*/             p=new classNumberDemo();
/*19*/             p.show();
/*20*/             p=new classNumberDemo();
/*21*/             p.show();             
/*22*/      }

/*23*/}

posted on 2008-11-05 22:16 郭兴华 阅读(359) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: