다형성
public class Application{
public static void main(String[] args){
Hunam human = new Human();
Asian asian = new Asian();
Human test = new Asian();
test.greeting();
Human rin = human; // == Human rin = new Human();t
}
}
class Human{
void showInfo(){
System.out.println("All human begins are equal.");
}
void talk(){
System.out.println("say something");
}
}
class Asian extends Human{
void showInfo(){
System.out.println("Rin is an Asian ><b");
}
void greeting(){
System.out.println("Hello ><b");
}
}
- test 라는 오브젝트
- Human 타입이다
- 하지만 객체화는 Asian으로 되어있다.
- 객체화되는 부분은 어디쪽 메서드를 호출할지 결정
- 중복되어있는 메서드들이 있다면 객체화된 부분의 메서드가 호출된다.
- 즉 test 는 Human 타입이고 Asian으로 객체화가 되었다.