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


Please Help Members By Posting Answers For Below Questions

What is thread pool in java with example?

549


What is the biggest integer?

562


What is the this keyword?

560


Difference between vector and arraylist.

589


What are the access modifiers available in java?

572






What is protected access modifier?

586


When should a function throw an exception?

605


What are the pillars of java?

491


How many unicode characters are there?

560


Explain the importance of throwable class and its methods?

571


What is the reason behind using constructors and destructors?

560


define polymorphism in java

641


What are register variables what are the advantages?

454


What is flush () in java?

562


What are the 6 functions?

521