Simplifying OOP in Java: Access Modifiers
Software Engineering

Simplifying OOP in Java: Access Modifiers

A simple explanation of access modifiers in Java, showing how private and public control visibility and help protect the structure of a class.

April 19, 2026·2 daqiiqaa dubbisuu·koofkee

Day 3: Access Modifiers

After learning about encapsulation, the next step is understanding access modifiers.

In Java, access modifiers control visibility. They help decide what should stay inside a class and what should be accessible from outside.

Two of the most common ones are private and public.

class Car {
    private int speed;

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        if (speed >= 0) {
            this.speed = speed;
        }
    }
}

In this example, speed is marked as private, which means it cannot be accessed directly from outside the class.

The methods getSpeed() and setSpeed() are public, which means they can be used from outside the class.

This is what makes access modifiers important. They help you decide what stays protected and what should be open for use.

Java, OOP, Access Modifiers, Software Engineering, Computer Science, Beginner Java, Koofkee