The process of binding up data and functions together that manipulates them is known as encapsulation in OOPS. It protects the data from outside interference and misuse.

Let’s understand the concept of encapsulation with both real-world examples and with the help of a program.

lead interview questions
It is an attribute of an object, and it contains all data which is hidden. That hidden data is restricted to the members of that class.

Example

                                        

class Account {
    private int account_number;
    private int account_balance;

    public void show Data() {
        //code to show data
    }

    public void deposit(int a) {
        if (a < 0) {
            //show error
        } else
            account_balance = account_balance + a;
    }
}

Suggest An Answer