Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects and classes. It focuses on organizing code into reusable and modular components.
The main characteristics (features) of OOP are:
These features help in building efficient, maintainable, and scalable programs.
Encapsulation is the process of binding data (variables) and methods (functions) together into a single unit (class).
It also restricts direct access to some components, which helps in data protection.
class Student:
def __init__(self, name):
self.name = name
def display(self):
print(self.name)
Abstraction means hiding internal implementation details and showing only essential features to the user.
class Car:
def start(self):
print("Car started")
Explanation
Inheritance allows one class (child class) to inherit properties and methods from another class (parent class).
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
pass
d = Dog()
d.speak()
Polymorphism means one function or method can have many forms.
def add(a, b):
return a + b
print(add(2, 3))
print(add("Hello ", "World"))
OOP is based on objects and classes
Main characteristics:
Additional features include modularity, reusability, and maintainability