just starting to learn java
got a question
public class Test10 { public static void main(String[] args){ Dog parent = new Dog(); Animal me = new Dog(); me.setParent(parent); Dog myParent = me.getParent(); // ОШИБКА, несовместимость типов } } class Animal{ Animal parent; public void setParent(Animal parent) { this.parent = parent; } public Animal getParent() { return parent; } } class Dog extends Animal{ @Override public Dog getParent(){ return (Dog) parent; } } Why does an error occur? the variable me, though of type Animal, but stores a reference to an object of class Dog, hence the overridden getParent method must be called, which makes a animal type downcast, and type Dog, and it seemed to me that it should return type Dog