The Techie King

Polymorphism in Java

Article By The Techie King

Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance.Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.Polymorphism is one of the core concepts of OOP and describes situations in which something occurs in several different forms. In java, it describes the concept that you can access objects of different types through the same interface.

Types of polymorphism

  • Compile-time Polymorphism
  • Runtime Polymorphism

Compile-time Polymorphism :

It is also known as static polymorphism. This type of polymorphism is achieved by function overloading or operator overloading. Method Overloading: When there are multiple functions with the same name but different parameters then these functions are said to be overloaded.

Runtime Polymorphism :

is also known as Dynamic Method Dispatch. It is a process in which a function call to the overridden method is resolved at Runtime. This type of polymorphism is achieved by Method Overriding.In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.

Scroll to Top