Advanced Programming

Table of Contents

Encapsulation

Encapsulation makes sure that sensitive stuff is hidden from users.

Idea: declare class variables/attributes as private, provide public getters and setters to use the variable.

public class Safe {
    private String superPrivateInfo;

    public String getSuperPrivateInfo() {
        return superPrivateInfo;
    }

    public void setSuperPrivateInfo(String newInfo) {
        this.superPrivateInfo = newInfo;
    }
}

Classes can be:

Attributes/methods/constructors can be: