• 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

Polymorphism

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is an example of polymorphism.
a. inner classes.
b. anonymous classes.
c. method overloading.
d. method overriding.

I think the answer is both C and D.
Because method overloading is compile time polymorphism and method overriding is runtime polymorphism.
Its this right?? If not correct me....Maha help me ....
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did read from tutorial (might be Baldwin's) and I remember that only run time polyporphism (overriding) is polymorphism.
But I donot agree with that since the polymorphism (having many forms) is implemented using both overloading and overriding.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raja,
In Object Oriented Concepts, polymorphism and overriding always go together. So only ans d) is correct.
regds
maha anna

[This message has been edited by maha anna (edited April 07, 2000).]
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

polymorphism and overriding always go together.


Maha, I'm playing devil's advocate again :
Both overloading and overriding are considered to be examples of polymorphism:
1. Overloading sometimes is called shallow kind,resolved by the compiler
2. Overriding is a deep (or true) polymorphism , resolved at runtime...
Sorry..
I wish I had more time now to visit this site more often, it's a joy and a challenge!
[This message has been edited by Jane Rozen (edited April 07, 2000).]
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jane,
I used to refer to Thinking in Java for any such issues. In this, in chapter 7. Ploymorphism , 3rd paragaraph, Bruce Eckel, says This ability is critical because it allows many types (derived from the same base type) to be treated as if they were one type, and a single piece of code to work on all those diff types equally. And also throughout this chapter he talks about the late-binding of methods depending upon the type of the object, gives the classic base class 'shape' , derived classes 'Circle', 'Rectangle' etc. He also mentions at page 221 3rd paragraph, that This doesn't appear as polymorphic call at all where the example given was overloaded instead of overriden and he says that this is not what we wanted.
regds
maha anna
 
Jane Rozen
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maha,sure neither of us makes up this stuff! I referred to "Just Java" and "Core Java" - in both there are references to "true" as opposed to "limited" polymorphism. As long as we all know what we are talking about...
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me check this dusty old tome I have on my desk here...
<blockquote>Remember the method overriding, and keep it holy. For that is the one true polymorphism, and thou shalt hold no other polymorphism before it.</blockquote>
I can't make out the author - it appears to have been assembled from postings by a number of different authors, and often appears to give conflicting info. But a lot of people seem to take it seriously for some reason.

Seriously, I personally would have answered D only, but I guess a case can be made for C, depending on how exactly one defines "polymorphism". Perhaps this question would work better as "choose the 1 best answer" - we all agree that's D right?

[This message has been edited by Jim Yingst (edited April 08, 2000).]
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim you vote for c or d? You said if you had to choose one best answer you will pick c(overloading).So, you think overloading is the best example for polymorphism.
Thanks.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Sree- that was a typo when I said C, which now is fixed. So now people will look at your post and wonder what you're talking about. But for the record - there was originally a good reason why he posted that question.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic