This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MasterExam OO question

 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Santiago Ennis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rushikesh sawant
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IS-A relationship relay on polymorphism because, polymorphism is obtained through inheritance.
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for your answers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic