The core ideas of Object-Oriented Programs are Encapsulation, Inheritance and Polymorphism.
The idea behind encapsulation is that you want to keep each type or class discrete and self-contained so that you can change the implementation of one class without affecting any other class.
The class that provides methods or functions that other use is usually called the main class. You can declare an instance of the class and make use of the member functions and types of the main class.
As your member functions in a class can be used by other class members, you want to provide some restrictions to those classes by declaring them public or private.
If you need to declare an instance of the class that is slightly different from the main class, you can derive a class from the main class or in this case the parent class. The derived class is called the child class. This is called inheritance in Object-Oriented programs.
The inheritance relationship is referred to as the is-a relationship. A dog is a mammal; a car is a vehicle. (Dog would be derived from the main class Mammal and Car from the main class Vehicle.)
If you change how a shared ability is implemented in the main class, you do not have to update code in every derived type; they inherit the changes.
Polymorphism, the third pillar of object-oriented programming, is closely related to inheritance. The prefix poly means “many”; morph means “form.”
Thus, polymorphism refers to the ability of a single type or class to take many forms.
A way to understand polymorphism is to look at the + operator. It depends on the context that the + operator is used.
The + operator can be used arithmetically as in 5+3 = 8. It can also be used to add a string together such as “hello” + “world” to get “hello world”.