This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

MasterExam OO question

 
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9679
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9679
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9679
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone for your answers!
 
reply
    Bookmark Topic Watch Topic
  • New Topic