What is encapsulation in OOP?
- Encapsulation is the mechanism of hiding internal details of an object and
exposing only necessary functionalities.
- It helps in protecting data and maintaining control over how it is accessed or
modified.
Example: A BankAccount class hides its balance and only allows deposit/withdraw
operations:
private decimal balance;
public void Deposit(decimal amount) { if(amount > 0) balance +=
amount; }