What is run time polymorphism?

Answer Posted / vijayakumar chinnasamy

Method overrrideing is the runtime polymorphism.The
class's "object" only determine which method to called .
eg:
class SuperClassTest
{
public void display(){
System.out.println("Super class");
}
}
class SubClassTest extends SuperClassTest
{
public void display(){
System.out.println("Sub class");
}
}
public class TestPro {



public static void main(String[] args) {

SuperClassTest sub=new SubClassTest();
System.out.print("I am Calling
subclasstest's display() method: ");
sub.display();

SuperClassTest sup=new SuperClassTest();
System.out.print("I am Calling
superclasstest's display() method: ");
sup.display();
}

}


o/p:

I am Calling subclasstest's display() method: Sub class
Note: object is type of SubClassTest
I am Calling superclasstest's display() method: Super class
Note: object is type of SuperClassTest

Note:
Method overloading is compile time polymorphism.The
class "reference" type determine which method to be called.

Is This Answer Correct ?    13 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What advantage do java's layout managers provide over traditional windowing systems?

539


What are the fileinputstream and fileoutputstream?

565


Can we create more than one object singleton class?

571


What is the java virtual machine?

576


What is the use of beaninfo?

582






Is it correct to say that due to garbage collection feature in java, a java program never goes out of memory?

570


Can we create a constructor in abstract class?

567


Is treeset sorted in java?

572


What is the escape character in java?

507


What are the types of web technologies?

520


Can you instantiate the math class?

596


What is a nested class?

586


What is difference between == equals () and compareto () method?

528


Why super is first line in java?

550


What do you mean by static variable?

567