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 will happen if a thrown exception is not handled?
Is 9 a prime number?
How many bits is a 64 bit byte?
What are the two types of java?
Can java cast null?
Can I import same package/class twice?
Why should we use singleton pattern instead of static class?
What is the Difference between Final Class && Abstract Class?
Does hashset allow duplicates in java?
What is the difference between sleep and wait in java?
Explain illegalmonitorstateexception and when it will be thrown?
What is array length?
Is Constructor possible in abstract class in java ?
What is meant by 'Class access modifiers'?
Where are the card layouts used?