
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
질문드립니다. 자바 강의를 따라가고 있는데, 객체지향 퀴즈에서 instanceof 에 대한 내용이 나왔습니다. 객체지향 퀴즈 이전 강의에서는 instanceof 에 대한 설명이 없었는데, 혹시 객체지향퀴즈 이 후 강의 중에 instanceof에 대한 내용을 설명해주신 부분을 알 수 있을까요?
public class Main {
public static void main(String[] args) {
Human grandParent = new GrandParent("할아버지", 70);
Human parent = new Parent("엄마", 50);
Human child = new Child("나", 20);
Human[] humans = { grandParent, parent, child };
for (Human human : humans) {
System.out.println(human.name + ", 나이: " + human.age + ", 속도: " + human.speed + ", 장소: " + human
.getLocation());
}
System.out.println("<활동 시작>");
for (Human human : humans) {
if (human instanceof Walkable) {
((Walkable) human).walk(1, 1);
System.out.println(" - - - - - - ");
}
if (human instanceof Runnable) {
((Runnable) human).run(2, 2);
System.out.println(" - - - - - - ");
}
if (human instanceof Swimmable) {
((Swimmable) human).swim(3, -1);
System.out.println(" - - - - - - ");
}
}
}
}
