Run Time Polymorphism Example Java Program
Run Time Polymorphism Example Program
class ClassA{ public void disp(){ System.out.println ("I am inside Class A"); } } class ClassB extends ClassA{ public void disp(){ System.out.println ("I am inside Class B"); } } public class RunTimePolymorphismDemo{ public static void main (String args []) { ClassA obj1 = new ClassA(); ClassA obj2 = new ClassB(); obj1.disp(); obj2.disp(); } }
Sample Output
Output is: I am inside Class A I am inside Class B
OOPS Programs
- Encapsulation Example Java Program
- Single Inheritance Example Java Program
- Interface Example Java Program
- Multiple Inheritance Using Interface Example Java Program
- Multilevel Inheritance Example Java Program
- Hierarchical Inheritance Example Java Program
- Method Overloading Example Java Program
- Method Overriding Example Java Program
- Function or Method Overloading with different data type in Java
- Run Time Polymorphism Example Java Program
- Compile Time Polymorphism Example Java Program
- Abstract Class Example Java Program
Read More Articles
- Multiple Inheritance Using Interface Example Java Program
- Single Inheritance Example Java Program
- Multilevel Inheritance Example Java Program
- Hierarchical Inheritance Example Java Program
- Find all Substrings of a given string Example Java Program
- Create Matrix Example Java Program
- Sum Of Three Numbers Example Java Program
- Twin Prime Example Java Program
- Heap Sort Example Java Program
- Compile Time Polymorphism Example Java Program