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 about interthread communication and how it takes place in java?
How do you sort a string in alphabetical order in java?
How many bytes is a string?
What is the disadvantage of java?
What does it mean that a class or member is final?
What is the Difference between Final Class && Abstract Class?
Explain inner classes ?
What is n in java?
Which collections are thread safe in java?
can rmi and corba based applications interact ?
Is string a datatype?
What is bool mean?
Where will it be used?
What is the use of singleton class?
What is the purpose of assert keyword used in jdk1.4.x?