Object-Oriented Programming (OOPs)
Source: Dev.to
Class
Example: Car is a class. Different cars may have different names and brands, but all share common properties like four wheels, speed limit, and mileage.
Object
An object is the basic element of Object‑Oriented Programming that represents real‑life entities. It is created from a class, and memory is assigned when the object is instantiated. Every object has identity, state, and behavior.
For example, “Dog” is a real‑life object, which has characteristics such as color, breed, bark, sleep, and eats.
Data Abstraction
Example: A person driving a car knows that the accelerator increases speed and the brakes stop the car, but does not know how the internal system works. This is called abstraction.
Encapsulation
Encapsulation is the process of combining data and methods into a single unit. It binds together the code and the data it operates on. In encapsulation, class variables are hidden from other classes and can be accessed only through the class’s member functions. Because the data is protected from outside access, encapsulation is also called data hiding.
Inheritance
Inheritance is an important concept in Object‑Oriented Programming. It allows one class to use the properties and methods of another class. This means a new class can reuse existing code instead of writing everything again. As a result, inheritance reduces duplication and makes programs easier to maintain and reuse.
Polymorphism
Polymorphism means “many forms.” In Object‑Oriented Programming, it refers to the ability of a single action or message to behave in different ways. For example, one person can have multiple roles such as a father, husband, or employee, showing different behaviors in different situations. This concept is known as polymorphism.