Polymorphism:-
- The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form.
- A real-life example of polymorphism is when two people have distinct characteristics at the same time. At the same time, he is a father, a spouse, and an employee. As a result, the same person behaves differently in different settings.
- Polymorphism is considered one of the important features of Object-Oriented Programming.
Polymorphism is mainly divided into two types:
- Compile-time Polymorphism
- Runtime Polymorphism
Compile-time polymorphism
This is achieved by function overloading or operator overloading.
- Function Overloading - When there are multiple functions with the same name but different parameters then these functions are said to be overloaded
- Operator overloading - When there are multiple operations that can be performed by using a single operator is called operator overloading for example operator ‘+’ when placed between integer operands, adds them, and when placed between string operands, concatenates them.
Run Time Polymorphism
It is achieved by Function Overriding
Additional Information
Encapsulation
- It is the process or method to contain the information.
- Wrapping of data and function into a single unit is called data encapsulation
- Encapsulation is a method to hide the data in a single entity or unit along with a method to protect information from outside.
- It can be implemented using by access modifier.
Inheritance
The capability of a class to derive properties from another class is called Inheritance
- The class that inherits properties from another class is called Subclass or Derived Class.
- The class whose properties are inherited by a subclass is called Base Class or Superclass.
Syntax for Inheritance
class derived_name : access_mode base_class
{
//body of the derived class
};