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 keyword in oop?

516


Does string isempty check for null?

558


What is default size of arraylist in java?

553


what is ststic with example

1593


Is nullpointerexception checked or unchecked?

549






What is a java applet? What is an interface?

627


Which is better stringbuilder or stringbuffer?

526


Name few java util classes introduced with java 8 ?

498


What is meant by class?

539


Does google use java?

530


What do you mean by pointer value and address?

575


What is method overloading with type promotion?

577


Do extraneous variables affect validity?

523


Why arraylist is not synchronized in java example?

465


Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.

511