The answer is Y::f1 X::f2 

The reason is that the function f3 is virtual in this class hierarchy. So,
dynamic dispatch occurs. Since xptr points to an object of type Y, Y::f3()
would be invoked. Now there is no definition for f3() provided in the class Y.
So the function invoked is X::f3(). Inside the function f3, functions f1() and
f2() are invoked. The functions f1() and f2() inside f3 are actually
this->f1() and this->f2() (There should be nothing perplexing about this)
where this points to the object using which f3 was
invoked. Now since f3() was invoked using xptr, this
is same as xptr and hence this also points to an object of type Y.
In other words, the dynamic type of this  is Y*. Since
function f1() is virtual, dynamic dispatch occurs and Y::f1() is invoked and
since f2() is non virtual, no dynamic dispatch occurs, and function invoked is
X::f2() (because the static type of xptr is X*). This explains the output.