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



what is the purpose of method overriding in java where v r completely re-defining a inherited meth..

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

what is the purpose of method overriding in java where v r completely re-defining a inherited meth..

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

what is the purpose of method overriding in java where v r completely re-defining a inherited meth..

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

what is the purpose of method overriding in java where v r completely re-defining a inherited meth..

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

what is the purpose of method overriding in java where v r completely re-defining a inherited meth..

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

what is the purpose of method overriding in java where v r completely re-defining a inherited meth..

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

what is the purpose of method overriding in java where v r completely re-defining a inherited meth..

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

Post New Answer

More Core Java Interview Questions

can abstract class have constructor how can you achive this ?

4 Answers   Fidelity,


What is a lightweight component?

0 Answers  


How do you check if a string is lexicographically in java?

0 Answers  


What is difference between core java and java ee?

0 Answers  


What is string in java?

0 Answers  






What is the main functionality of the remote reference layer?

0 Answers  


Does java runtime require a license?

0 Answers  


how to connect two diffrent applet files

0 Answers  


Can we create a constructor in abstract class?

0 Answers  


How does map works in java?

0 Answers  


What is the use of runnable interface?

0 Answers  


Does A Class Inherit The Constructors Of Its Superclass?

0 Answers   Wipro,


Categories