Java Modifier
Java Modifier
Các loại Modifier trong Java
Access Modifiers
public
publicVí dụ:
public class Car {
public String color;
public int maxSpeed;
public Car(String color, int maxSpeed) {
this.color = color;
this.maxSpeed = maxSpeed;
}
public void displayInfo() {
System.out.println("Color: " + color);
System.out.println("Max Speed: " + maxSpeed + " km/h");
}
}private
privateVí dụ:
protected
protectedVí dụ:
(default)
Ví dụ:
Non-Access Modifiers
static
staticVí dụ:
final
finalVí dụ:
abstract
abstractVí dụ:
Bài tập thực hành
Tạo lớp Student
Tạo lớp Employee
Last updated