Object oriented java sample exam

后端 未结 6 454
南笙
南笙 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:06

    Because the id is static. That means that is a "Class variable/field" and there is only one per Class. All the instances of that Class share it the same id (indeed calling it "id" feels kinda weird).

    See here

提交回复
热议问题