Services Work Learn About Contact
0/10
Lesson 9 of 10

Access Modifiers

Access modifiers control visibility. public is visible everywhere. private is only within the class. protected is within the class and subclasses. Default (no modifier) is package-private.

JAVA
public class BankAccount {
  private double balance;

  public void deposit(double amount) {
    if (amount > 0) {
      balance += amount;
    }
  }

  public double getBalance() {
    return balance;
  }
}
🧠

Quick Quiz

Answer correctly to unlock the next lesson.

Support the mission

This learning platform is 100% free: no ads, no tracking, no paywalls. If it helped you learn something useful, you can support future lessons or donate to Doctors Without Borders, which provides emergency medical care in crisis zones worldwide.

🎉

You completed Java!

You finished all 10 lessons and quizzes. You now know the basics of Java.