CJCoding With Joseph
15free / daySign inCreate account

Covariant Return Type Override

Animal declares a virtual Clone() that returns an Animal, and a virtual Species property. In Dog, override Clone() using a covariant return type so it returns a Dog (not an Animal), and override Species to return Dog. The tester clones a Dog and prints the clone's Species, then clones again through an Animal reference and prints that Species. Do NOT write a Main method.

Because dispatch is dynamic, both lines print Dog. 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
Topics:
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.