Loading

Polymorphism

  • Polymorphism comprises two words- poly and morphism.
  • "Poly" means "many" and "morphism" means “forms”. 
  • Therefore polymorphism means many forms. i.e. method has the same name but different or many functionalities.

Examples: Take a real-life example of a person, at the same time a person can be a student, a teacher, an employee, a son, a father, etc. The person is the same but his behavior or functionality is different in different situations.

  • There are two types of polymorphism:
    1. Compile time Polymorphism
    2. Runtime Polymorphism
     
  • We can achieve polymorphism in two ways:
    1. Method overloading
    2. Method overriding