- 1. Kế thừa
- 2. Bao đóng
Ví dụ mình tạo một interface về chuyển động như dưới đây
Code: Select all
public interface Movable {
void move(int meter);
}
Code: Select all
public class Car implements Movable {
private int doors;
private int seats;
private int distance;
public Car(int doors, int seats) {
this.doors = doors;
this.seats = seats;
}
@Override
public void move(int meter) {
this.distance = meter;
}
}