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;
}
}