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 is bufferedwriter?

540


Why are data types important?

535


What are the access modifiers available in java?

558


Can a class declared as private be accessed outside it’s package?

510


What sorting algorithm does javascript use?

526






When is the finalize() called?

694


What is meant by string is immutable?

515


How can you read content from file in java?

597


What is overloading and overriding in java?

656


Can we assign null to double in java?

542


How many types of threads are there in java?

501


What are the types of literals?

556


Explain java coding standards for interfaces?

626


What is the java reflection api? Why it’s so important to have?

550


What is abstract class constructor called?

563