Object oriented java sample exam

后端 未结 6 459
南笙
南笙 2021-01-25 15:52
public class Bird
{
  private static int id = 0;
  private String kind;

  public Bird(String requiredKind)
  {
    id = id + 1;
    kind = requiredKind;
  }

  public S         


        
6条回答
  •  悲&欢浪女
    2021-01-25 16:25

    Since the id field is static, it will have the same value throughout (and outside of) all instances of Bird.

    After creating two Bird objects, the constructor will have been called twice, therefore the id will be 2.

    See: Understanding Instance and Class Members

提交回复
热议问题