Skip to content
Home/Blog/Encapsulation, Inheritance and Polymorphism in Object-Oriented Programming

Encapsulation, Inheritance and Polymorphism in Object-Oriented Programming

Encapsulation, Inheritance and Polymorphism in Object-Oriented Programming

ENCAPSULATION

Encapsulation, one of the terms met in fields such as object-oriented programming and network technology, is a method that binds code and data together while hiding some of an object's properties and functions from the rest, or restricting access to them — protecting the system from incorrect or abusive use from outside. Encapsulation, or data encapsulation, is simply the act of closing a class off to the outside and encapsulating, that is preventing, access to it. Through encapsulation the source code and the data belonging to the system are held as a single whole, which gives the programmer the power to protect objects.

As is well known, classes are made up of properties and methods. The purpose of data encapsulation is to bring access to a class's properties under control — preventing them from being reached from outside, so that access runs through the class's own methods instead.

INHERITANCE:

Another term met in object-oriented programming is inheritance. As the name makes clear, inheritance means one class possessing the properties and methods held by another. Once a class has the members of a more general class that also contains the members of a particular class, it no longer has to define them again.

Here the class holding the wider set of members exhibits inheritance, because it leaves no need to redefine a class that already contains some of those members. The term extends is used for a class taking on the properties of another class by inheritance. In plain terms it means: "this class extends that one — it takes its properties and methods, and adds new ones".

POLYMORPHISM:

It is the use of one particular operation (method) by many objects. Polymorphism means that an object can also be used for different purposes, and it divides into two kinds: static and dynamic.

— Static polymorphism is described as the overloading of methods and operators.

— Dynamic polymorphism is the name given to carrying out operations by inheriting from abstract classes.