Back to posts
2 min read

Object-oriented Programming Concepts

Object-oriented programming has four basic concepts: encapsulation, abstraction, inheritance and polymorphism.

Object-oriented Programming Concepts

Object-oriented programming has four basic concepts: encapsulation, abstraction, inheritance and polymorphism.


Class

A class is a blueprint or prototype using which you can create as many objects as you like.


Object

An Object is an instance of Class. It is a bundle of data and its behaviour (known as methods).


Object and Class

The image is from Internet


Encapsulation

Encapsulation (enclosing something in a capsule) is a process of wrapping code and data together into a single unit. it keeps the data safe from outside interference.

Example : A computer has multiple parts like CPU, GPU, memory, hard disk, and so on. Multiple parts of computer encapsulate themself together to form a single computer.


Abstraction

Abstraction hides unnecessary information and shows only the essential ones. It is simpler Interface and reduce complexity.

Example : A mobile phone, we know what we can do with a mobile phone but we don't need to know how it works inside like the process of calling phone or connecting cellular network in hardware level.


Inheritance

Inheritance is the capacity of a class to inherit properties and strategies from other class.

Example : A wife is owning the properties and salaries of her husband. Cats can have the same color, name or size but they are not the same cat.


Polymorphism

Polymorphism (many forms) allows us to perform a single action in different ways.

Example : A girl can be a programmer, mother, wife, student or something else. It means same person can have different roles.


polymorphism

Polymorphism

The image is from Internet.


Thanks for reading!