Has-A relations must be on the same inheritance hiearchy

Answer (for Objective 5.5):
 B, E, and F are correct statements about the code.
 A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.
D is similarly incorrect because MyApp doesn’t “have” a Mungeable as part of its state.

When answering the above question i selected the option that says MyApp has-a Employee.
The book says that this is wrong because Employee and MyApp are not on the same inheritance tree. Is this correct?

I was not aware that the classes are supposed to be on the same inheritance tree for a has-a relationship.

HAS-A indicates that the class contains some reference at the instance level.
In the example- Employee is a local variable used in public static void main. Its not really part of MyApp class.
And HAS-A doesnt depend on the inheritance hierarchy- because its composition.

Mohamed Sanaulla wrote:HAS-A indicates that the class contains some reference at the instance level.
In the example- Employee is a local variable used in public static void main. Its not really part of MyApp class.
And HAS-A doesnt depend on the inheritance hierarchy- because its composition.

Which is the source you are using for this question and solution?

It was a question from the K&B practice exams. The description given for the answer is

Answer (for Objective 5.5):
 B, E, and F are correct statements about the code.
 A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.
D is similarly incorrect because MyApp doesn’t “have” a Mungeable as part of its state.

O. Ziggy wrote: A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.

I think you are confused with this statement right?

The statement above is stating the reasons why A and C are incorrect. The- "the MyApp class “uses” the Employee class, but MyApp isn’t in Employee’s class hierarchy" is justification for A not being correct and the other statement is a justification for C not being correct.