父类对象引用子类对象规则
程序员文章站
2024-03-21 19:07:46
...
public class People {
public void eat(){
System.out.println("吃饭");
}
}
public class Ray extends People {
public void beCool(){
System.out.println("cool");
}
public void eat(){
System.out.println("ray吃饭");
}
}
public class Main {
public static void main(String[] args) {
Ray ray = new Ray();
People[] people = new People[3];
people[0].eat();
}
}