
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
제목그대로요 왜그럴까요?
.png)
.png)
작성한 코드 및 에러 메세지
package sparta;
abstract class Bird {
private int x, y, z;
void fly(int x, int y, int z) {
printLocation();
System.out.println("이동합니다.");
this.x = x;
this.y = y;
if (flyable(z)) {
this.z = z;
} else {
System.out.println("그 높이로는 날 수 없습니다.");
}
printLocation();
}
abstract boolean flyable(int z);// 추상메서드는 바디를 가질수없다.
public void printLocation() {
System.out.println("현재위치{" + x + ", " + y + ", " + z + ")");
}
}
class Pigeon extends Bird {
@Override
boolean flyable(int z) {
// TODO Auto-generated method stub
return z < 10000;
}
}
class Peacock extends Bird {
@Override
boolean flyable(int z) {
return false;
}
}
public class Main {
public static void main(String[] args) {
Bird pigeon = new Pigeon();
Bird peacock = new Peacock();
System.out.println("--- 비둘기---");
pigeon.fly(x: 1, y: 1, z: 3);
System.out.println("--- 공작새---");
peacock.fly(x: 1, y: 1, z: 3);
System.out.println("--- 비둘기---");
pigeon.fly(x: 3, y: 3, z: 30000);
}
}
