一段JAVA程序代码求运行结果
importjava.util.ArrayList;classGrannySmithextendsApple{publicStringtoString(){return"...
import java.util.ArrayList;
class GrannySmith extends Apple {
public String toString() {
return "GrannySmith";
}
}
class Gala extends Apple {
public String toString() {
return "Gala";
}
}
class Fuji extendsApple {
public String toString() {
return "Fuji";
}
}
class Braeburn extends Apple {
public String toString() {
return "Braeburn";
}
}
public class GenericsAndUpcasting {
public static void main (String[] args) {
ArrayList<Apple>apples = newArrayList<Apple>();
apples.add(new GrannySmith());
apples.add(new Gala());
apples.add(new Fuji());
apples.add(new Braeburn());
for (Apple c: apples) {
System.out.println(c);
}
}
}
运行结果:???? 展开
class GrannySmith extends Apple {
public String toString() {
return "GrannySmith";
}
}
class Gala extends Apple {
public String toString() {
return "Gala";
}
}
class Fuji extendsApple {
public String toString() {
return "Fuji";
}
}
class Braeburn extends Apple {
public String toString() {
return "Braeburn";
}
}
public class GenericsAndUpcasting {
public static void main (String[] args) {
ArrayList<Apple>apples = newArrayList<Apple>();
apples.add(new GrannySmith());
apples.add(new Gala());
apples.add(new Fuji());
apples.add(new Braeburn());
for (Apple c: apples) {
System.out.println(c);
}
}
}
运行结果:???? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询