오버라이딩 된 메서드가 항상 우선권을 가진다.
public class Parent {
public String value = "parent";
public void method() {
System.out.println("Parent.method");
}
}
public class Child extends Parent {
public String value = "child";
@Override
pubilic void method() {
System.out.println("Child.mehtod");
}
}
public class Main {
public static void main(String[] args) {
Parent poly = new Child();
System.out.println("Parent -> Child");
System.out.println("value = " + poly.value);
poly.method();
}
}
실행결과
Parent -> Child
value = parent
Child.method

알고리즘 문제를 해결할때 Queue를 생성할 때 삽입 삭제가 많을 경우 LinkedList로 생성하는데 오버라이딩된 메서드를 LinkedList 것을 사용하기 때문이라는 것을 알 수 있었다.