Skip to content
UniCircle
EasyConceptualOOP concepts

Access modifiers: private, default, protected, public

Question JAVA-OOP-010

List Java's four access levels and who can see a member at each level.

Show the explanation
ModifierSame classSame packageSubclass in another packageEveryone
private✔
(none) "package-private"✔✔
protected✔✔✔ (through inheritance)
public✔✔✔✔
Java
package bank;
public class Account {
    private long balance;            // only Account
    long branchCode;                 // anything in package bank
    protected void audit() { }       // bank + subclasses elsewhere
    public long getBalance() { return balance; }
}

Top-level classes can only be public or package-private. A sensible default is to make fields private and give everything the narrowest access that works. Note that protected is wider than package-private, not narrower — a common slip.

Original UniCircle question. Last reviewed 22 Oct 2026.