Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java IS-A relationship exam question confusion

From MasterExam:

Which statements are true? (Choose all that apply)

A. is-a relationship always rely on inheritance
B. is-a relationship always rely on instance variables
C. is-a relationship always require at least two class types
D. is-a relationship always rely on polymorphism
E. is-a relationship are always tightly coupled

Correct answers: A, C, D

I don't see how any of A, C or D are correct.

An Object object IS-A Object. A String object IS-A String. There is only one class type in each of these statements and no inheritance or polymorphism applies.

Is my rationale wrong or are the answers incorrect?

like image 996
CodeClimber Avatar asked Jul 13 '10 13:07

CodeClimber


1 Answers

"Relationship" refers to a relationship between two classes. An is-a relationship is a type of relationship that uses inheritance (as opposed to e.g. has-a, which uses composition). For instance, a String is-a Object. A class can't inherit from itself, which implies C. As a side note, a class could have composition (has-a) with itself. E.g. a Person could have another Person as a mother field.

Any time you have inheritance, an instance of the subclass can be used as an instance of the superclass. That's polymorphism, which means D is also right.

like image 97
Matthew Flaschen Avatar answered Sep 30 '22 04:09

Matthew Flaschen