0% found this document useful (0 votes)
4 views1 page

Object

Object-Oriented Programming (OOP) is a programming paradigm that utilizes 'objects' to encapsulate data and methods, enhancing reusability, scalability, and modularity. The key principles of OOP include encapsulation, abstraction, inheritance, and polymorphism, which facilitate better program structure. OOP offers benefits such as code reusability, modularity, scalability, and improved security.

Uploaded by

Adarsh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Object

Object-Oriented Programming (OOP) is a programming paradigm that utilizes 'objects' to encapsulate data and methods, enhancing reusability, scalability, and modularity. The key principles of OOP include encapsulation, abstraction, inheritance, and polymorphism, which facilitate better program structure. OOP offers benefits such as code reusability, modularity, scalability, and improved security.

Uploaded by

Adarsh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Object-Oriented Programming (OOPs)

Object-Oriented Programming (OOP) is a programming paradigm based on the


concept of "objects," which can contain data (attributes) and code (methods). It helps
in structuring programs for better reusability, scalability, and modularity.

Key Principles of OOP

1. Encapsulation – Wrapping data and methods into a single unit (class) to


restrict direct access.

2. Abstraction – Hiding implementation details and showing only necessary


functionality.

3. Inheritance – Allowing a class to inherit properties and behavior from


another class.

4. Polymorphism – The ability of different objects to respond differently to the


same function call.

Example in Python

# Encapsulation

class Car:

def __init__(self, brand, speed):

self.brand = brand # Public attribute

self.__speed = speed # Private attribute (Encapsulation)

def get_speed(self):

return self.__speed # Getter method

# Inheritance

class ElectricCar(Car):

def charge(self):

print(f"{self.brand} is charging.")

# Polymorphism

class PetrolCar(Car):

def refuel(self):

print(f"{self.brand} is refueling.")

# Object Creation

tesla = ElectricCar("Tesla", 150)

bmw = PetrolCar("BMW", 180)

# Accessing Methods

print(tesla.get_speed()) # Encapsulation

tesla.charge() # Inheritance

bmw.refuel() # Polymorphism

OOP Benefits

✅ Code Reusability – Reduces redundancy


✅ Modularity – Easier to maintain and update
✅ Scalability – Suitable for large applications
✅ Security – Protects data using encapsulation

You might also like