~/ learn/ java-from-zero/ cards/ Overriding vs hiding: @Override, covariant returns & access rules
1 of 4

Type an @Override method with a covariant return

Type an @Override method with a covariant return

Answer

@Override Dog getAnimal() { return new Dog("Rex", 3); }

Covariant return: if the parent declares Animal getAnimal(), overriding with Dog getAnimal() is valid because Dog IS-A Animal. @Override confirms the compiler checks the relationship.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/4be45e35-c110-4e2f-9205-5c7609b77ef3/flashcard utf-8 LF