| Author |
MasterExam OO question
|
Nidhi Sar
Ranch Hand
Joined: Oct 19, 2009
Posts: 252
|
|
When considering relationships between classes, which statement(s) are true?
A) is-a relationships always rely on inheritance
B) is-a relationships always rely on instance variables
C) is-a relationships always require atleast two class types
D) is-a relationships always rely on polymorphism
E) is-a relationships are always tightly coupled
The answers are A, C & D.
A & C are understandable, but I don't get D. Polymorphism (as in, which overridden method is invoked in the inheritance tree) is a result of is-a relationship, but why would is-a relationship have to rely on polymorphism.
Could someone enlighten me on this please...
|
"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
is-a relationships always rely on polymorphism
The IS A relationship does not rely on methods being inherited.
For example a Car is a Serializable but does not implement any methods. If you take this stand point then option D can be termed incorrect. I think however that the question is trying to stress on the "extends" and "implements" part of polymorphism, in which case option D is correct.
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Santiago Ennis
Greenhorn
Joined: Nov 05, 2009
Posts: 9
|
|
Nidhi Sar wrote:When considering relationships between classes, which statement(s) are true?
A) is-a relationships always rely on inheritance
B) is-a relationships always rely on instance variables
C) is-a relationships always require atleast two class types
D) is-a relationships always rely on polymorphism
E) is-a relationships are always tightly coupled
The answers are A, C & D.
I think answer is D only.
A) is-a relationships *always* rely on inheritance
Always? Actually, is-a relationship rely on Interfaces also (which is NOT inheritance).
For example, C implements I i.e. C is-an I. Where is inheritance in this example?
C) is-a relationships *always* require at least two class types
Always? Actually, "two class type" is NOT a mandatory requirement.
For example, C implements I i.e. C is-an I. In this example there is only one class and it is an example of is-a relationship.
Am I sleeping?
- SE
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Santiago Ennis wrote:For example, C implements I i.e. C is-an I. Where is inheritance in this example?
So you mean when a Class implements an Interface, there's no inheritance??
As far as option C is concerned, that one seems wrong to me too as IS-A relationship can be between a class and an interface...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
As far as option C is concerned, that one seems wrong to me too as IS-A relationship can be between a class and an interface...
I remember this point being raised before. I agree about that one too.
|
 |
Santiago Ennis
Greenhorn
Joined: Nov 05, 2009
Posts: 9
|
|
Ankit Garg wrote:
So you mean when a Class implements an Interface, there's no inheritance??
Oh! yeah! C implements I, is an example of both - inheritance AND is-a.
What about option C?
- SE
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Santiago Ennis wrote:What about option C?
As I said earlier, C option is wrong. As Deepak said, this has been pointed out in the forum before that this is an error in the master exam...
|
 |
rushikesh sawant
Ranch Hand
Joined: Dec 22, 2009
Posts: 65
|
|
C) is-a relationships always require at least two class types
i think option C in right. as per my understanding Java treats interface as an abstract class. (Interface is 100% abstract CLASS!)
check this out:
if we try to compile this, we get an error message" my interface.java:6: Inter is abstract; cannot be instantiated new Inter();
again if i compile this:
you check it.
So, i think option C is right...
|
SCJP 5.0 100%
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Inter is abstract; cannot be instantiated new Inter()
The error message doesn't say Inter is abstract *class*. An interface is implicitly abstract.
Interface is 100% abstract CLASS
Interface is similar to 100% abstract class. Multiple inheritance is not possible with classes but is possible with interfaces...
|
 |
rushikesh sawant
Ranch Hand
Joined: Dec 22, 2009
Posts: 65
|
|
|
thanks for this information. But then, what is the exact difference between 100% pure abstract class and an interface? both create types, that's what i know.
|
 |
Neha Daga
Ranch Hand
Joined: Oct 30, 2009
Posts: 504
|
|
guys..you all forget about option d, even I had the similar doubt how can is-a relationship rely on polymorphism?
I thought it to be vice-versa.
|
SCJP 1.6 96%
|
 |
rushikesh sawant
Ranch Hand
Joined: Dec 22, 2009
Posts: 65
|
|
|
IS-A relationship relay on polymorphism because, polymorphism is obtained through inheritance.
|
 |
Neha Daga
Ranch Hand
Joined: Oct 30, 2009
Posts: 504
|
|
rushikesh sawant wrote: polymorphism is obtained through inheritance.
I know that and how this seems to me is polymorphism relies on inheritence then, how can Is-A rely on polymorphism?
|
 |
rushikesh sawant
Ranch Hand
Joined: Dec 22, 2009
Posts: 65
|
|
you agree on to the option A which says is-a rely on inheritance?
we use is-a test to verify validness in inheritance hierarchy, and if there is inheritance, there can be polymorphism. so if two things can be used polymorphically they must pass is-a test.
|
 |
Nidhi Sar
Ranch Hand
Joined: Oct 19, 2009
Posts: 252
|
|
|
Thanks everyone for your answers!
|
 |
 |
|
|
subject: MasterExam OO question
|
|
|