What is encapsulation in OOP?
2025
What is encapsulation in OOP?
- A.
The ability to inherit properties from multiple classes
- B.
The process of creating objects
- C.
The bundling of data and methods that operate on the data
- D.
The use of abstract classes only
Attempted by 188 students.
Show answer & explanation
Correct answer: C
Encapsulation is one of the fundamental concepts of Object-Oriented Programming (OOP). It refers to combining data (variables) and the methods (functions) that operate on that data into a single unit called a class.
Encapsulation also helps in data hiding by restricting direct access to internal data using access modifiers such as private, protected, and public.
Example:
class Student
{
private:
int marks;
public:
void setMarks(int m)
{
marks = m;
}
};Here, data (marks) and method (setMarks) are bundled together inside the class.