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 are the problems faced by java programmers who don't use layout managers?
explain the concept of virtual method invocation in polymorphism in detail?
Can we have multiple classes in single file ?
Explain all java features with real time examples
How do you pass by reference?
What are the main features of java?
What is exception handling in java?
List some java keywords sun like c, c + + keywords?
What is difference between c++ and java ?
What are white spaces in java?
What is unmodifiable list in java?
What is an example of a keyword?
Is null false in java?
What is methods and methodology?
What is parsing and its types?