โ Back to Polymorphism
Question 695
Covariant Return Type Override
Covariant Return Type Override
Animaldeclares a virtualClone()that returns anAnimal, and a virtualSpeciesproperty. InDog, overrideClone()using a covariant return type so it returns aDog(not anAnimal), and overrideSpeciesto returnDog. The tester clones aDogand prints the clone'sSpecies, then clones again through anAnimalreference and prints thatSpecies. Do NOT write aMainmethod. Because dispatch is dynamic, both lines printDog. The full expected output is: Dog Dog
Expected Output:
Dog Dog
Topics:
Polymorphism
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.