1.

What is Encapsulation in oops with an example?

Answer»

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.

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;
    }
}



Discussion

No Comment Found