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
What is string manipulation?
How do you remove duplicates from an array in java?
What does the three dot emoji mean?
Why enumeration is faster than iterator?
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.
What is Session reduplication and how its done?
How to call one constructor from the other constructor ?
what is the difference between process and thread? : Java thread
What is float in java?
Can we use catch statement for checked exceptions?
How do you square a number?
What are the actions that can occur when a thread enters blocked state?
What is object-oriented paradigm?
What is the function of log?
State two differences between C and Java.