Access modifiers
Access modifiers — control the visibility of classes, methods, and variables.
Public class Car {
private String color; // Accessible only within the Car class
public int speed; // Accessible from any class
public String getColor() {
return color; // Accessed through a public method
}
public void setColor(String color) {
this.color = color;
}
} Java provides several modifiers, but the two most commonly used are public and private.
Semantic portal