[code=Java]
public class Tier {
protected boolean fly;
protected boolean swim;
protected boolean dive;
protected boolean run;
public Tier() {
fly = false;
swim = false;
dive = false;
run = false;
}
public void move() {
//Todo: Nothing
}
public boolean canFly() {
return fly;
}
public boolean canSwim() {
return swim;
}
public boolean canDive() {
return dive;
}
public boolean canRun() { //oder canWalk
return run;
}
}
[/code]
[code=Java]
public class Vogel extends Tier {
public Vogel() {
super();
fly = true;
}
@Override
public void move() {
System.out.println("Ich flieeeeeege!");
}
}
[/code]
[code=Java]
public class Papageientaucher extends Vogel {
public Papageientaucher() {
super();
swim = true;
dive = true;
}
@Override
public void move() {
System.out.println("Ich tauschschwimfliege!");
}
}
[/code]
PS: Steinigt mich wenns falsch is...
PPS:
Testklasse:
[code=Java]
public class Test {
public static void main(final String[] args) {
List<Tier> tierList = new ArrayList<Tier>();
Papageientaucher ptauch = new Papageientaucher();
Vogel vogel = new Vogel();
tierList.add(ptauch);
tierList.add(vogel);
for (Tier tier : tierList) {
tier.move();
}
}
}
[/code]