CJCoding With Joseph

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:

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.