A language that follows the OOPs(Object Oriented Programming) concepts will treat everything as an object and object has attributes and behavior.
An object is a real-time entity that is used to bind data or to reuse the data that was defined previously.
Therefore, Object-Oriented Programming concepts also help a developer to think about how to design and maintain any certain application.
In addition, there are several different concepts that make a programming language and Object-Oriented Programming language.
Object Oriented Programming Concepts:
Abstraction is a very interesting concept of programming. It simply means “Hiding the Complexity and Showing the Functionality“.
For instance, Let’s take some real-world example of abstraction:
Example 1: “An ATM machine”, you really don’t care what’s happening inside the box, what you just care is your money coming out. Here, Complexity is hidden.
Example 2: “An Automobile”, Simply you just need to accelerate the accelerator and you don’t know what’s happening in the engine.
In Programming, there are many ways to achieve abstraction. It could be though abstract class, inheritance, or declaring Interface.
Recommended Read: Abstraction in Java
As the word defines, Encapsulation means encapsulating data with access modifiers. In other words, Encapsulation is a technique that binds data and code together.
By using, private, protected, and public keywords we can restrict our data members for being used outside the class. Primarily, to keep data safe from misuse encapsulation is done.
For instance, Let’s understand through a real-world example of encapsulation.
- Private: Private members are restricted within a class.
- Public: They are visible everywhere in the program.
- Protected: Protected members are visible to the subclasses.
Example 1: Think about a capsule here.
Recommended Read: Encapsulation in Java
Polymorphism is a concept where an object behaves differently in a different situation. For example, a single object can have multiple behaviors.
For instance, Let’s understand Polymorphism with real-world examples.
Example 1: “Air Conditioner”, AC is a single entity but may have different behavior in a different situation depending on the weather.
Example 2: “Coffee Machine”, Similarly, It is also a single entity but can prepare hot coffee as well as cold coffee, depending on the need of the customer.
Polymorphism is of two types:
- Runtime Polymorphism: Method Overriding (Inheritance) is a technique by which we can achieve runtime polymorphism.
- Compile Time Polymorphism: Method Overloading is an example of compile-time polymorphism.
Recommended Read: Polymorphism in Java
Inheritance is a mechanism where an object depends on another object. However, this is the best approach for code reusability,
It is a mechanism where one class can inherit the properties of another class to avoid code duplicacy. For instance, Let’s discuss Inheritance with a real-world example:
Example 1: Think about yourself and your father here.
- The class whose features are inherited by other classes is known as Superclass or Parent class or Base class.
- The class who inherits super class is known as Subclass or Child class.
Recommended Read: Inheritance in Java
Object Oriented Programming Languages:
- Object Pascal
- Common Lisp