Object oriented java sample exam

后端 未结 6 461
南笙
南笙 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

    static variables are shared across objects unlike instance variables. So when this executes

    birds[0] = new Bird("falcon");
    

    the id increments to 1. After that the below is executed incrementing it to 2

    birds[1] = new Bird("eagle");
    

提交回复
热议问题