Thuta Learning
IntermediateProgrammingbeginner

Modifiers

Relax. We'll talk through this in plain words — no textbook voice.

Modifiers control the access level and behavior of classes, fields, and methods. Java has Access Modifiers (public, private, protected) and Non-access Modifiers (static, final, abstract). Modifiers act as gatekeepers, keeping your code safe and making sure it's used only the way it's meant to be.

java
public class Main {
  private String secret = "Only inside this class";
  public String name = "Java Learner";

  static void showAppName() {
    System.out.println("ThutaTech Java Tutorial");
  }

  public void showName() {
    System.out.println(name);
  }

  public static void main(String[] args) {
    showAppName();
    Main obj = new Main();
    obj.showName();
  }
}

private fields can't be accessed directly from outside the class. public methods can be called through an object. static methods can be called at the class level without creating an object.

You should see
ThutaTech Java Tutorial Java Learner

Real-World Use

Keeping API keys, password fields, and internal calculations private, and exposing them only through public methods, matters a lot in production apps.

Easy traps

  • Calling an instance method from a static context without creating an object, or reaching into a private field directly from outside the class, both cause errors.
Modifiers | Thuta Learning