public class Testpolymorphism {
public static void main(String[] args) {
person1 p = new person1();
p.eat();
Chinese chinese = new Chinese();
chinese.eat();
American a = new American();
a.eat();
Indian i = new Indian();
i.eat();
}
}
class person1{
public void eat() {
System.out.println("人们吃饭");
}
}
class Chinese extends person1{
public void eat() {
System.out.println("中国人吃饭");
}
}
class American extends person1{
public void eat() {
System.out.println("美国人吃饭");
}
}
class Indian extends person1{
public void eat() {
System.out.println("印度人吃饭");
}
}

这个用不同的对象调用同样的方法 行为完全不同。 所以这算不算多态?(语言-java)
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- 嗨——我叫安然 2022-05-09 10:47关注
你的person是父类,你或许可以这样写。
person c=new chinese()
C.eat()
好像这样才叫多态,我一般这么写,仅供参考。本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用