Skip to content
Home » Java Programing Language » Polymorphism In Java

Polymorphism In Java

 Polymorphism

  1. One thing can be behave in different manner. (One function can be used for a different ways/implementation)
  2. There are two types of polymorphism
    1. Compile time polymorphism
      1. The method call resolve at compilation time is called as compile time polymorphism.
      2. To Achieve this polymorphism can use Overloading.
    2. Runtime polymorphism
      1. The method call is resolve at execution time is called as runtime polymorphism.
      2. To Achieve this polymorphism can use Overriding.

 

Overloading 

  1. Same method name can be used for a different implementation in a same class or in sub class.
  2. Method name must be same with different input parameter list.
  3. Return data type may or may not be same.
  4. Access Modifier may or may not be same.
  5. Input parameter list must be different in following perspective.
    1. Can change the type of parameter.
    2. Can change the number of parameter.
    3. Can change the sequence of parameter.
  6. Overloaded methods gets invoked automatically on the bases of input values provided by user.
  7. Can overload a static method.
  8. Can overload the final methods.
  9. Can throw new and broader checked Exception.

 

Overriding

  1. Same Method name with same parameter list into a sub class.
  2. Method name must be same and Input parameter must be same.
  3. Overriding must done in sub class.
  4. Return data type must be same if it is void or primitive or it can be sub type.
  5. Access modifier must be same or less restrictive.
  6. Cannot override final method.
  7. Cannot override static method.
  8. Cannot throw new and broader checked Exception.

Achieve Runtime Polymorphism

  1. There must be a inheritance between class and sub class must override method.
  2. Create a Polymorphic Object. Polymorphic Object is a reference of Super class and Object of Sub class (Each super class reference can hold the object of all its sub classes).
  3. Call a overridden method by using polymorphic object.

 Polymorphism

 

 

Join Telegram : Click Here

 

All Full Stack Java Study Material

 

Java the programing language

 

Job’s For Fresher

 

Share This Information To Your Friends and Your College Group’s, To Help Them !