Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is-a relationship confusion

 
Kevin Kilbane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 an Object. There is only one class type in this statement and no inheritance or polymorphism applies. Please explain.
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"IS-A relationship" is the ability of an object of one class type to behave as another class type. Just because you are able to form an english sentence with "is" followed by "a", doesn't mean that there is a "IS-A" relationship involved.

Henry
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Kevin..... Only option "D" is correct in my sincere opinion.

Let me discuss my reasoning

A is Incorrect because it relies on Interfaces too... String is-a Serializable
B is incorrect because
C is incorrect , reasoning same a A. Serializable is not a Class , its an Interface.
D is correct, it relies on polymorphism . (always word is somehow debatable as your example seems to be correct, Object is-a Object and does not involve polymorhism, but IMO it is a particular special case. )
E. Coupling has nothing to take with is-a, as two classes may be coupled (tightly or loosely) without being in same Inheritance tree.

Thanks !!!

In actual exam you will get, how many are true....then you can move from most obvious to least.

I agree with you all are incorrect !!! (always word seems to be wrong, it should be most of the time)
 
Kevin Kilbane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
"IS-A relationship" is the ability of an object of one class type to behave as another class type. Just because you are able to form an english sentence with "is" followed by "a", doesn't mean that there is a "IS-A" relationship involved.

Henry


Thnaks for the prompt reply Henry.

Have a look at this method:


Statement 1: "The parameter to the doStuff method must be an object that passes the IS-A Car test".

Statement 2: "The parameter to the doStuff method must be a Car object or an object that passes the IS-A Car test".

I always thought statement 1 was correct but you are saying that statement 1 is incorrect and statement 2 is correct.

Is that right?

 
Kevin Kilbane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
"IS-A relationship" is the ability of an object of one class type to behave as another class type. Just because you are able to form an english sentence with "is" followed by "a", doesn't mean that there is a "IS-A" relationship involved.

Henry


Sorry, did some further checking after I posted the last reply. The Bates and Sierra book states in Chapter 2 (top p.95 in my copy):

"Other than objects of type Object, all Java objects are polymorphic in that they pass the IS-A test for their own type and for class Object."

The important bit here is "they pass the IS-A test for their own type" i.e. String IS-A String.

I'm still leaning towards thinking the answers in MasterExam are wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic