public class A {
public Number get() { return 1; }
}
public class B extends A {
public Integer get() { return 2; }
}
A x = new B();
System.out.println(x.get());What is printed?
- A
Compile-time error
- B
Runtime error
- Ccheck_circle
2
- D
1
Explanation
Dynamic dispatch invokes B.get() returning 2.