# Encapsulation

*noun*

say it: **“en-KAP-suh-LAY-shun”** **/ɛnˌkæpsəˈleɪʃən/**

Keeping an object's data and the details of how it works behind its own methods, so other code can't depend on them.

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

## In a sentence

- “Thanks to **encapsulation**, the price could change inside the class without touching the code that used it.”

Level: Apprentice · [More OOP terms at this level](https://www.ask-codey.com/glossary?category=oop&level=2)

Updated: November 9, 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)
- [Encapsulation in Python](https://www.ask-codey.com/glossary/encapsulation)

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