What is encapsulation in OOP?

2025

What is encapsulation in OOP?

Answer: C. The bundling of data and methods that operate on the dataEncapsulation is one of the fundamental concepts of Object-Oriented Programming (OOP). It refers to combining data (variables) and the methods (functions)…

  1. A.

    The ability to inherit properties from multiple classes

  2. B.

    The process of creating objects

  3. C.

    The bundling of data and methods that operate on the data

  4. D.

    The use of abstract classes only

Attempted by 314 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.

Explore the full course: Bihar Stet Paper Ii Computer Science

Loading lesson…