Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

"Is-a" relationship exam question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I found this is-a question in my Learn Key mock exam that i don't agree with the answer. The question and the answer are bellow:

A) is-a relationships always rely on inheritance.
B) is-a relationships always rely on instance variables.
C) is-a relationships always require at least two class types.
D) is-a relationships always rely on polymorphism.
E) is-a relationships are always tighly coupled.

Answers with explanations:
A, C and D are correct. B is incorrect. Inheritance is independent of the existence of instance variables. E is incorrect. Coupling is not used to evaluate classes within the same inheritance tree.

What i think from the answer:
A) A cannot be true because an is-a relationship also applies when a class implements an interface. Example: java.lang.String implements Comparable, then, String is-a Comparable! there is no inheritance!
C) i don't understand why we can't say that a String is-a String! Isn't it an is-a relationship?
D) i can't get why does is-a always rely on polymorphism, i think that's because of my doubt on letter C.

Can you clarify these with your comments?

Thank you,

Bruno
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bruno,

A. is correct, because when you implement an interface you inherit all its methods and constants the interface may have. think of interfaces as a 100% abstract classes. (interfaces are the way that Java implements multiple inheritance).

C. the "is-a" refers to a relation so an object can NOT inherit it self. it may contain a reference to a reference of its type which is a "has-a" relationship but it can NEVER inherit itself.

D. Polymorphism is a Greek word and means "many forms" or "many shapes", regarding java that means that an object of type B that extends type A may be referred by references of type B of course BUT also by references of type A which means it has "many forms". So when when we speak for inheritance we also speak for polymorphism.

ex:


Hope to Help!

Cheers.
[ May 16, 2007: Message edited by: Omer Haderi ]
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My view
A debatable
C Wrong
D Right

A) A is debatable. But I would had said true.

C) Now if A is correct then that includes interfaces. Now if interfaces are included then C should also include interfaces hence C is wrong.

D) Sounds true to me.

I guess this has been discussed before.
 
They weren't very bright, but they were very, very big. Ad contrast:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic