Polymorphism in Java | Core Java Free Training

This Core Java Free Training “Polymorphism in Java” is providing introduction to polymorphism and what is compile time polymorphism in java application which contains method overloading.


 

Polymorphism :

  • Defining an Object(class) that shows different behavior(methods) with the same Identity.
  • ‘Poly’ means ‘Many’
  • Morphic’ means ‘Forms’

 

Java supports 2 types of polymorphism:

  1. Compile time polymorphism
  2. Runtime polymorphism

 

Compile time polymorphism:

  • It is also called static binding.
  • It is method overloading technique.
  • Method overloading refers defining more than one method with the same name within the same class but with different signatures.
  • It can be implemented in a single class.
  • Hence single object can alone shows compile time polymorphism behavior.
  • Compiler connects with the method depends on method call. So at run time, JVM no need to search for the method to be executed.

 

Can we overload Constructor?

  • Yes allowed.
  • We have already seen in Constructor Chaining concept.

 

Can we overload main method ?

  • Yes.
  • JVM can access only standard main method.
  • User defined main methods must be executed explicitly in the application.

 

Share this