CodesJava

Easy learning with example program codes

what is runtime polymorphism in java?


Java runtime polymorphism in java is a mechanism to resolve overridden method call at run time instead of compile time. It is based on the concept of up-casting (A super class reference variable can refer subclass object.).

Example

/**
 * This program is used for simple method overriding example.
 * with dynamic method dispatch.
 * @author CodesJava
 */
class Student {
      /**
       * This method is used to show details of a student.
       * @author CodesJava
       */
      public void show(){
            System.out.println("Student details.");
      }
}
 
public class CollegeStudent extends Student {
      /**
       * This method is used to show details of a college student.
       * @author CodesJava
       */
      public void show(){
            System.out.println("College Student details.");
      }
 
      //main method
      public static void main(String args[]){
       //Super class can contain subclass object.   
       Student obj = new CollegeStudent();
 
       //method call resolved at runtime
       obj.show();
      }
}

Output

College Student details.
School Student details.
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki