Why Over riding is Run Time Polymorphism?
Answer Posted / anjani kumar jha
It is very diffcult for compiler to know which version of
the method called(superclass or subclass).
Hence to identify which version of method is called java
used run-time polymorphism(same copy used in both class)
where object type defined which version is called.
I am giving u one example............
class A
{
public void sum() //this is method which we will override
{
//some operation here//
}
}
class B extends A
{
public void sum() //over-riden method,see both method
r //same
{
//some operation here//
}
public static void main(String as[])
{
A a=new B() //RUN TIME POLYMORFISM
a.sum()//Since a is a object type of class B SO class B sum
method will be called................................
}
}
//I think uy doubt will be clear
}
Thanks and Regards
Anjani Kumar Jha
CDAC
9623154095
| Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
Explain method overloading?
How many return statement are allowed in a function?
Are functions objects in java?
How does multithreading take place on a computer with a single cpu in java programming?
placement papaers of spring computing technology
What is the function of java?
Is Constructor possible in abstract class in java ?
can I implement my own start() method? : Java thread
What is the map interface in java programming?
Why set do not allow duplicates in java?
What are the java ide’s?
Why is string buffer better than string ?
What is tostring () method?
why are there separate wait and sleep methods? : Java thread
Why spring singleton is not thread safe?