zoukankan      html  css  js  c++  java
  • 课后作业

    使用类的静态字段和构造函数,我们可以跟踪某个类所创建对象的个数。请写一个类,在任何时候都可以向它查询“你已经创建了多少个对象?”。 


    public class Duixiang {
    public static void main(String[] arge){
    Information a=new Information();
    a.OutputInformation();
    Information b=new Information();
    b.OutputInformation();
    Information c=new Information();
    c.OutputInformation();
    Information d=new Information();
    d.OutputInformation();
    }
    }
    class Information{
    static int num=0;
    Information()
    {
    num++;
    }
    public void OutputInformation()
    {
    System.out.println("你已经创建了"+num+"个对象!");
    }
    }

  • 相关阅读:
    hdu 5101 Select
    hdu 5100 Chessboard
    cf B. I.O.U.
    cf C. Inna and Dima
    cf B. Inna and Nine
    cf C. Counting Kangaroos is Fun
    Radar Installation 贪心
    spfa模板
    Sequence
    棋盘问题
  • 原文地址:https://www.cnblogs.com/tangjindong/p/4888205.html
Copyright © 2011-2022 走看看