Encapsulation

Keeping an object's data behind methods that control how it is read or changed.

What is Encapsulation in Java?

Encapsulation — Keeping an object's data behind methods that control how it is read or changed.

class Thermostat {
    private int temperature;

    int getTemperature() {
        return temperature;
    }

    void setTemperature(int temperature) {
        this.temperature = temperature;
    }
}

Level: Journeyman · More Java terms at this level

Updated

In other subjects