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
What are accessor methods in java?
What is a platform?
Difference between keyword and identifier.
What is use of a abstract variable?
When is the finalize() called? What is the purpose of finalization?
Name and explain the types of ways which are used to pass arguments in any function in java.
What is byte code and why is it important to java’s use for internet programming?
What are generic methods?
What is difference between this and super keyword?
Is set thread safe java?
How to overcome the exception object reference not set to an instance of object?
What is considered an anti pattern?
What are the types of java?
Name few java util classes introduced with java 8 ?
what happens when a thread cannot acquire a lock on an object? : Java thread