← Back to Polymorphism
Question 785
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 exactly what is shown in Expected Output.
Expected Output:
Dog Dog
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Polymorphism
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.