why can't I call a subclass method using a reference of a parent type that refers to an instance of a sub-type?
问题 I am Learning Java, while trying to understand inheritance. I couldn't figure out why the overridden method at the subclass walk() executed but not the other xyz() method. class Person{ public void walk() { System.out.println("walking like a person "); } } public class Soldier extends Person{ @override public void walk() { System.out.println("marching like a soldier "); } public void xyz() { System.out.println("xyzng like a pro"); } public static void main(String[] args) { Person sp = new