what is the purpose of method overriding in java where v r
completely re-defining a inherited method instead y can't v
create a new method and define.If the question is very silly
plz excuse me and do reply.Thank U!
Answers were Sorted based on User's Feedback
Answer / sridharan
We know method overriding will be coming in inheritance.
Consider a mother and her daughter.
Lets think mothers will cook, so her daughter will also
cook. One day mother cooked a biryani for her daughter. By
using the method
cookBriyani(rice,vegetables,water,salt). {
// mother style of cooking
}
But her daughter didn’t like it. So her daughter decided to
prepare biryani by herself. She is also going to use same
ingredients but she is going to prepare in her style.
Daughter method is
cookBriyani(rice,vegetables,water,salt){
// daughter style of cookling
}
Daughter made also biryani so without changing the
name i.e cookBriyani(), also she used same ingredients (i.e
rice,vegetables,water,salt) i.e same parameter but she
prepared in different style.
Is This Answer Correct ? | 67 Yes | 6 No |
Answer / sadikhasan palsaniya
we can change default behavior of super class method by
overriding that method into the subclass.
Is This Answer Correct ? | 17 Yes | 5 No |
Answer / ershad md sk
Bcoz......wen we think in Object Oriented Lang ..has u ask
if we create a new method we hav to call the method each
time wen we invoke the Object & it is a performance ISSUE
it wil eat lot of memory & it is a COMPLEXITY
Issue ........if u override Using the superclass Handle we
can create any instance which is of any type(int Float
Long Short)it wil save space and reduce COMPLEXITY and
increase PERFORMANCE...
Is This Answer Correct ? | 10 Yes | 17 No |
Answer / sathish kumar
using this concept we can call base class function
repeatedly in subclass only change of inner coding in
subclass each and very subclass overrides baseclass when
they r called
Is This Answer Correct ? | 1 Yes | 8 No |
Answer / kv
The answer lies in Object Oriented concept. When you are
overriding a method, you overriding the internal details of
default behavior. But your interface to external world is
not changed. Example, Base class employee has a method
commuteToWork(). All the manager in the company has given
the company car and a driver. Their implementation of
commuteToWork will be different from the non manager
employees. If you add a new method saying
commuteToWorkByCar(), every Monday morning you would need to
call different method for each subtype of employee. Hope it
will help.
Is This Answer Correct ? | 13 Yes | 23 No |
Answer / kino
Unlike data fields, method names can be duplicated. This is
an important feature that allows method overriding, which
in turn facilitates polymorphism in the design of object-
oriented programs. Method overriding allows a subclass to
provide its own implementation of a method already provided
by one of its superclasses. When a method is called on an
object, IDL searches for a method of that class with that
name. If found, the method is called. If not, the methods
of any inherited object classes are examined in the order
their INHERITS specifiers appear in the structure
definition, and the first method found with the correct
name is called. If no method of the specified name is
found, an error occurs.
We can think of overriding as redefining. When we want to
redefine an inherited behaviour in a more specialised way,
we must provide implementation with the exact method
signature as the inherited method (that we want to
redefine).
For example:
If I define class A:
class A{
void m(){
}
}
We can be making objects from A like this:
A a = new A;
And we can call its method m like this:
a.m();
If we also define class B as a child of A like this:
class B extends A {
}
Then we know it inherits method m from its parent, class A
So we can do this:
B b = new B();
b.m();
The above works because m is inherited.
if u dont understand go through this link.
http://www.tgs.com/support/oiv-java-
release_notes/extension/guide_content.html
Is This Answer Correct ? | 3 Yes | 15 No |
Answer / imambasha
hi
MethodOverriding is the concept which implements Dynamic
Code(Method) binding.
i.e., The method which is going to bind or execute is
decided at the runtime basing on the Object that we are
using to call that method...
Suppose assume we have two Classes A,B Where class B is
inheriting class A.And even we have overridden(given
different implementation with same method signature)a
method of class A in class B.
Now the criteria is which method(superclass method or
subclsas overridden method) is to be called or executed is
determined based on the object(class A object Or class B
object) we are using to call that method............
Is This Answer Correct ? | 9 Yes | 22 No |
Why is logger singleton?
What is the properties class?
Why are strings immutable in Java?
What is broken and continue statement?
What is the frontend and backedn in Java?
What do you understand by the term polymorphism?
How can you make a class serializable in java?
Difference between Array and vector?
What is complexity in java?
Briefly explain the term Spring Framework
Explain Linked HashSet
How to make a read-only class in java?