In this article, we are gonna cover the OOPs (Object Oriented Programming) concepts, mainly classes, objects, inheritance, abstraction, encapsulation, polymorphism, etc. This is also very useful for technical interviews.
There are many examples of object oriented language such as C++, Java, PHP, Python, C#, etc. But the first object oriented language is Simula, where Smalltalk is considered as the first truly OOPs language.
The language which represents the objects is known as object oriented language.
The following points which we gonna cover in this article:
Important List of OOPs Concepts
The entity which has behaviour and state is called an object. The real-world examples of objects are table, chair, pen, pencil, etc (object can be anything).
It can be physical or logical. An object is an instance of the class. Objects can be defined multiple times for the same class, as objects can communicate without knowing the actual data of others.
The collection of objects is called class. As the class is a logical entity, it does not consume any space.
A class can be the blueprint of a single object.
The combined example of class and object is:
Fruits is the class, where Mango, Apple, Banana are the objects.
The process where one class (derived class) acquires the properties of another class (base class), is known as inheritance.
The main example of inheritance is code reusability. We can reuse the code very easily, with the help of inheritance.
Abstraction can be defined, hiding the internal details and only essential details were displayed to the user.
Data abstraction can also be defined, ignoring the irrelevant details and focusing on important details.
- It is the method or process of gaining information.
- It is the method of hiding unwanted information.
- Problems are solved at the design or interface level.
The wrapping up data into a single unit is called encapsulation. The data in one class is hidden from another class, so it is also called data-hiding.
To achieve the encapsulation, declare all the variables in one class as private and access that variable outside the class by declaring the public methods e.g. setData() and getData().
- It is the method or process to contain the information.
- It is a method to hide the data in a single entity or unit along with a method to protect information from outside.
- Problems are solved at the implementation level.
Polymorphism means many forms, while the same piece of code is used in different places in different contexts.
One of the common uses of polymorphism in OOPs is when a parent class reference is used to refer to the child class object.