# Encapsulation

Keeping an object's data private so it can only change through the object's own methods.

## What is **Encapsulation**?

**Encapsulation** means keeping an object's data private and only letting outside code change it through the object's own methods. A bank account doesn't let you set the balance directly; you must call `Deposit` or `Withdraw`, which can check the rules.

```csharp
public class BankAccount
{
    private decimal balance;          // hidden

    public void Deposit(decimal amount)
    {
        if (amount <= 0) throw new ArgumentException("Deposit must be positive");
        balance += amount;
    }
}
```

Level: Apprentice · [More OOP terms at this level](https://www.ask-codey.com/glossary/subjects/oop/apprentice)

Updated: September 27, 2026

## In other subjects

- [Encapsulation in C#](https://www.ask-codey.com/glossary/encapsulation-c-sharp)
- [Encapsulation in Java](https://www.ask-codey.com/glossary/encapsulation-java)
- [Encapsulation in JavaScript](https://www.ask-codey.com/glossary/encapsulation-javascript)

Source: https://www.ask-codey.com/glossary/encapsulation-oop
