Access modifiers in Java are keywords used to control the visibility and accessibility of classes, methods, variables, and constructors. They help implement encapsulation by restricting access to program components based on the required level of security and accessibility.
1. public
2. protected
3. default (No Modifier)
4. private
In a banking application, an account balance should typically be private to prevent direct modification, while public methods can be provided to deposit or withdraw money safely.
public class BankAccount {
private double balance = 1000;
public double getBalance() {
return balance;
}
protected void displayAccountInfo() {
System.out.println("Account Information");
}
}A concise interview answer is
Access modifiers in Java control the visibility of classes, methods, variables, and constructors. Java provides public, protected, default, and private access modifiers, which help enforce encapsulation, improve security, and manage access to application components.
Last updated: 16 July 2026
Previous question: Why are packages used in Java?
Next question: Can you provide examples of when to use each type of access modifier?