例如,我只是想知道如何使用子类来实现超类。
class Animal {
void poo() {
System.out.println("general poo");
}
}
class Horse extends Animal{
void poo() {
System.out.println("horse poo");
}
}
Animal animal1 = new Horse();
// using this I get the implementation of the Horse class's methods
animal1.poo(); //should return horse poo
试图向上转换它以获得超类实现但无济于事
((Animal)animal1).poo() // still returns the horse class's implementation of the method
如何使用 animal1 对象获取超类实现?