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
How do you create a method in java?
Can a hashset contain duplicates java?
How can we break singleton in java?
How garbage collection is done in java?
Explain about the performance aspects of core java?
What are inner classes or non static nested classes in java?
What advantage do java's layout managers provide over traditional windowing systems?
Can we define a package statement after the import statement in java?
What is a dynamic array java?
What is an infinite loop in java? Explain with an example.
What is the use of generics? When was it added to the Java development Kit?
How many java versions are there?
How do you reverse a string in java without using string buffer?
Difference between overriding and overloading in java?
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.