gpt4 book ai didi

java - 关于 Java 类的示例考试

转载 作者:行者123 更新时间:2023-11-30 06:21:48 24 4
gpt4 key购买 nike

<分区>

 public class Bird
{
private static int id = 0;
private String kind;

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

public String toString()
{
return "Kind: " + kind + ", Id: " + id + "; ";
}

public static void main(String [] args)
{
Bird [] birds = new Bird[2];
birds[0] = new Bird("falcon");
birds[1] = new Bird("eagle");
for (int i = 0; i < 2; i++)
System.out.print(birds[i]);
System.out.println();
}
}

这是一道样题,问输出,正确答案是Kind: falcon, Id: 2;种类:鹰,编号:2;

这有什么意义?对于 falcon,id 不应该是 1,那么 eagle,因为它的静态 id 应该是 2?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com