Question: Consider the inheritance of classes from Exercise R-2.12, and let d be an object variable of type Horse. If d refers to an actual object

Consider the inheritance of classes from Exercise R-2.12, and let d be an object variable of type Horse. If d refers to an actual object of type Equestrian, can it be cast to the class Racer? Why or why not?


In Exercise R-2.12

Draw a class inheritance diagram for the following set of classes:

• Class Goat extends Object and adds an instance variable tail and methods milk( ) and jump( ).

• Class Pig extends Object and adds an instance variable nose and methods eat(food) and wallow( ).

• Class Horse extends Object and adds instance variables height and color, and methods run( ) and jump( ).

• Class Racer extends Horse and adds a method race( ).

• Class Equestrian extends Horse and adds instance variable weight and is-Trained, and methods trot( ) and isTrained( ).

Step by Step Solution

3.55 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

No d is referring to a Equestrian ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Algorithms Questions!