;
으로 마무리한다.
class Main {
public static void main(String[] args) {
Unit[] group = {new Marine(), new Tank(), new Dropship()};
for (Unit x : group) {
x.move(100, 300);
}
}
}
abstract class Unit {
int x, y;
abstract void move(int x, int y);
void stop() {
/* 현재 위치에 정지 */
}
}
class Marine extends Unit {
@Override
void move(int x, int y) {
System.out.printf("Marine[x=%d, y=%d]\n", x, y);
}
}
class Tank extends Unit {
@Override
void move(int x, int y) {
System.out.printf("Tank[x=%d, y=%d]\n", x, y);
}
}
class Dropship extends Unit {
@Override
void move(int x, int y) {
System.out.printf("Dropship[x=%d, y=%d]\n", x, y);
}
}
Source