wood burning stoves 2.0*
The moose likes Java in General and the fly likes Overriding and Polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Overriding and Polymorphism" Watch "Overriding and Polymorphism" New topic
Author

Overriding and Polymorphism

Mukul Anand
Greenhorn

Joined: Nov 28, 2012
Posts: 29
Just came across this question:

The feature in object-oriented programming that allows the same operation to be carried out differently, depending on the object is

a. Inheritance
b. Polymorphism
c. Overfunctioning
d. Overriding

I am not sure whether the answer should be (b) or (d).
Can anyone explain?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Welcome to the ranch Mukul. Where did you find this question, which book / source? My money would be on d because overridden versions are called depending on the runtime type of object. Its not a feature of OOP, but Java language I believe.

~ Mansukh
Mukul Anand
Greenhorn

Joined: Nov 28, 2012
Posts: 29
Well, why not Polymorphism? How to differentiate between the two in this context?

By the way, this question was asked in some exam. I found it in the question-bank.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

The language is kind of ambiguous. The first part of the question says
feature of OOP
which makes me think of Polymorphism and when I read the last part,
depending on the object is
it makes me think of overriding. But when I read
allows the same operation to be carried out differently
, I am again reminded about method overriding, though you can't call it a feature of OOP. Overriding is run time polymorphism. If they are asking for a feature of OOP, then my answer would be b too. A correct and more precise question could have been framed as:

The feature in object-oriented programming that allows same object to take different forms and have different behaviors at runtime is:....
And then the answer would surely be Polymorphism.
Mukul Anand
Greenhorn

Joined: Nov 28, 2012
Posts: 29
Again, if the involved objects are of the same class then I don't see how they could show polymorphism with methods.
For polymorphic display, the objects should be of different classes with overridden methods. Isn't it?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Of course, runtime polymorphism is at play when we have a super class reference that points to a sub class object invoking the overridden method. That is why I stated above that method overriding is an type of runtime polymorphism as it is at runtime that JVM knows the type of the object and hence, calls the respective overriding method.
Mukul Anand
Greenhorn

Joined: Nov 28, 2012
Posts: 29
But the question still remains unanswered
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

I think you are over-thinking on about it. Rather read about Polymorphism from the oracle docs.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mansukhdeep Thind wrote:overridden versions are called depending on the runtime type of object. Its not a feature of OOP, but Java language I believe.


That is a general OO concept, not specific to Java.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mukul Anand wrote:But the question still remains unanswered


And it probably will remain so forever unless you contact the original author of the question.

It's a poorly worded question, and there is no definite one right answer. I would go with (b), but in the end that's just a gut call. It could just as easily be (d).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Agree about that being a poor question. For MCQ exams, every question should have one right answer and all other answers should be definitely wrong.
Mukul Anand
Greenhorn

Joined: Nov 28, 2012
Posts: 29
Hmm.. So the question itself is kind of vague.

Anyway, thanks all for the comments
 
wood burning stoves
 
subject: Overriding and Polymorphism