Answer is D)
Inheritance will make sure every function in parent class P is also a part of Q. But since Q has overridden the function f, Q's definition of function f will be used whenever an object of type Q is used to call f.
Dynamic binding determines the type of the object at run-time and not compile time. Refer http://www.javatpoint.com/static-binding-and-dynamic-binding
Looking at the pseudo code, in all the cases x.f(1), ((P) y), z.f(1), the objects are of type Q, hence function f from child class will be used. And since the definition of function f is present in parent class as well there wont be any exceptions.
Here's a small java example.
public class HelloWorld{
public static void main(String []args){
P x = new Q();
Q y = new Q();
P z = new Q();
P w = new P();
x.f(1);
((P) y).f(1);
z.f(1);
}
}
public class P {
void f(int i) {
System.out.println(i);
}
}
public class Q extends P {
void f(int i) {
System.out.println(2*i);
}
}