Introduction
Object-Oriented Programming (OOP) is a widely used programming paradigm that organizes
software design around objects rather than only functions and procedures. An object represents a
real-world entity and contains both data (attributes) and behavior (methods). OOP helps
developers create software that is more organized, reusable, maintainable, and easier to manage,
especially when developing large and complex applications.
The main purpose of OOP is to model real-world problems in a programming environment. By
using objects and classes, developers can create structured programs where different components
interact with each other to perform specific tasks. Popular programming languages that support
OOP include Java, C++, Python, C#, and PHP.
Basic Concepts of Object-Oriented Programming
1. Class
A class is a blueprint or template used to create objects. It defines the properties and behaviors that
objects will have. A class itself does not occupy memory for its data until an object is created from
it.
Example:
A “Student” class may contain attributes such as name, age, and roll number, along with methods
like registerCourse() or displayInformation().
, 2. Object
An object is an instance of a class. It represents a real-world entity and contains actual values for
the attributes defined in the class.
Examples of objects:
• A specific student
• A bank account
• A car
• A mobile phone
Objects interact with each other by calling methods and exchanging information.
Four Main Principles of OOP
1. Encapsulation
Encapsulation is the process of combining data and methods into a single unit called a class. It also
restricts direct access to internal data by using access modifiers such as private, public, and
protected.
Benefits:
• Protects data from unauthorized access
• Improves security
• Makes code easier to maintain
• Provides better control over data
2. Inheritance
Inheritance allows one class to acquire the properties and behaviors of another class. It promotes
code reuse and reduces duplication.
A class that provides features is called the parent class, while the class that inherits those features
is called the child class.
Types of Inheritance: