ランタイム ポリモーフィズムは、メソッドのオーバーライドで常に発生しますか?それとも、メソッドのオーバーライド中に、サブクラス オブジェクトをスーパー クラス変数に割り当てた後にメソッドが呼び出された場合にのみ発生しますか?
class A {
public void myFunc() {
System.out.println("Something");
}
}
class B extends A {
public void myFunc() {
System.out.println("Something else");
}
public static void main (String args[]) {
A obj = new B();
obj.myFunc(); //Is only this call resolved at run time?
A obj2 = new A();
obj2.myFunc(); //Or is this call too resolved at run time?
B obj3 = new B();
obj3.myFunc(); //Is this call resolved at compile time?
}
}