
Object-Oriented Programming (OOP) is a programming approach in which we model a program using objects (real-world entities). Each object combines:
Why OOP is used:
Core OOP ideas (overview): class, object, encapsulation, inheritance, polymorphism.
A class is a blueprint/template that defines:
An object is an instance of a class. It has actual memory and represents a real entity.
Example idea:
Student (defines roll, name, marks)s1, s2 (real students)Example concept:
balance is data memberdeposit() is member functionEncapsulation means wrapping data and functions together into a single unit (class).
Data hiding is achieved using access specifiers so that internal data is protected.
Typical practice:
This reduces accidental misuse and makes code more reliable.
Access specifiers control who can access class members.
Important Sem-1 understanding:
Two ways:
Access the complete note and unlock all topic-wise content
It's free and takes just 5 seconds
Download this note as PDF at no cost
If any AD appears on download click please wait for 30sec till it gets completed and then close it, you will be redirected to pdf/ppt notes page.
Object-Oriented Programming (OOP) is a programming approach in which we model a program using objects (real-world entities). Each object combines:
Why OOP is used:
Core OOP ideas (overview): class, object, encapsulation, inheritance, polymorphism.
A class is a blueprint/template that defines:
An object is an instance of a class. It has actual memory and represents a real entity.
Example idea:
Student (defines roll, name, marks)s1, s2 (real students)Example concept:
balance is data memberdeposit() is member functionEncapsulation means wrapping data and functions together into a single unit (class).
Data hiding is achieved using access specifiers so that internal data is protected.
Typical practice:
This reduces accidental misuse and makes code more reliable.
Access specifiers control who can access class members.
Important Sem-1 understanding:
Two ways:
::Example idea:
int Student::getRoll(){ return roll; }A constructor is a special member function that initializes objects.
Properties:
Why needed:
ClassName(const ClassName &obj)Copy constructor is invoked when:
In exams, write at least two situations.
A destructor is a special member function called automatically when an object is destroyed.
Key points:
~ClassName()Even if we don’t write a destructor, compiler provides a default one.
~.Understanding order is important:
For dynamically created objects:
new → destructor called when delete is usedCreate object → Constructor called → Use object → Scope ends/delete → Destructor called
+------------------+
| Class: Student |
|------------------|
| - roll : int |
| - name : string |
|------------------|
| + setData() |
| + show() |
+------------------+
Get instant access to notes, practice questions, and more benefits with our mobile app.
From this topic
OOP models programs using objects that combine data and behaviour. Advantages (any three):
Hence OOP helps build maintainable software.
Differences (any three):
A class is a blueprint/template that defines data members (properties) and member functions (behaviour). An object is an instance of a class that has actual memory.
Example:
Student (roll, name, marks)s1, s2 (actual students)Class: Student
- roll
- name
+ show()
Objects: s1, s2
Thus, classes help model real-world entities and objects represent actual entities in memory.