• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism

 
raja pratap
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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 ....
 
rag mul
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • 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).]
 
Jane Rozen
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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).]
 
sreelakshmi sarma
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic