• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please Help With This OO Question From K&B CD

 
Greenhorn
Posts: 5
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question

Which are true? (Choose all that apply)

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. Polymorphism always relies on IS-A relationships.
E. IS-A relationships are always tightly coupled.

The correct options are A,C and D.

I'm confused with the D option, which states that Polymorphism ALWAYS has to rely on IS-A relationships. Why?

If I have one class with overloaded methods, which does not extend or implement other classes or interfaces resp., won't this be a case of compile-time polymorphism without an IS-A relationship?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chinmay Terse wrote:If I have one class with overloaded methods, which does not extend or implement other classes or interfaces resp., won't this be a case of compile-time polymorphism without an IS-A relationship?


Yes; however, I'm an old purist who thinks that the term "compile-tiime polymorphism" is an oxymoron.

Operator overloading, OTOH - as exists in languages like C++ (and to a very limited extent in Java) - IS polymorphic because it involves more than one class; and its mechanics are much more like overriding.

So, given the wording of the question, it's not clear whether leaving out 'D' is wrong or not. However, if you already put C, I'd say that you're bound to include D, since method overloading can't involve two classes.

I'd also say that 'A' is arguable. For example, is the Decorator Pattern an 'IS-A' relationship? I'd say it probably is, even though it's usually implemented as a wrapper for flexibility - and there may well be other examples due to Java's single inheritance stipulation.

Hope I haven't "muddied the waters" for you.

Winston
 
Ranch Hand
Posts: 175
17
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Head First Java Page 191 wrote:Method overloading is nothing more than having two methods with the same name but different argument lists. Period. There’s no polymorphism involved with overloaded methods!


Polymorphism is the ability to have many forms i.e. a method call can have many possible resolutions at runtime.

This Java tutorial talks about how the overridden printDescription() method has many forms at runtime. If this method is simply overloaded and not overridden, then it cannot have many forms at runtime. It will be statically resolved at compile-time. Some call this compile-time polymorphism, however, real polymorphism is runtime polymorphism.
 
Chinmay Terse
Greenhorn
Posts: 5
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:However, if you already put C, I'd say that you're bound to include D, since method overloading can't involve two classes.


Sorry but I didn't get this statement. I've just completed reading Overloading form K&B which states we can very well overload a class's methods in its subclass.

Head First Java Page 191 wrote:Method overloading is nothing more than having two methods with the same name but different argument lists. Period. There’s no polymorphism involved with overloaded methods!


Bingo. Maybe I was confused about what counts as 'polymorphism', at least in Java. Many(most) of the polymorphism articles I've come across discuss method overloading and overriding as two types of polymorphism. Even K&B discusses the two under polymorphism, although it doesn't specifically say that those are its types. Head First makes it clear. Thanks a lot!

Winston Gutkowski wrote:Hope I haven't "muddied the waters" for you.


Not at all! In fact I'm now going to lookup Decorator Pattern and the word oxymoron.
Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic