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 is singleton class in ruby?
I want to persist data of objects for later use. What is the best approach to do so?
Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?
Can inner class extend any class?
Why array is used in java?
What is java Applet?
What is variable and example?
what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread
What is java developer skills?
Does substring start with 0?
Can you override private or static method in java?
Name few java util classes introduced with java 8 ?
What is immutable data?
What is the size of arraylist in java?
What is the base class in java from which all classes are derived?