From MasterExam:
Which statements are true? (Choose all that apply)
A
. is-a relationship always rely on inheritanceB
. is-a relationship always rely on instance variablesC
. is-a relationship always require at least two class typesD
. is-a relationship always rely on polymorphismE
. 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?
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With