Answer: Compile Time Error
Because interface P can NOT possibly be implemented in any of the subclasses of F, since F can't be subclassed as it's declared
final If the F was not declared final, then the code would compile fine because the compiler would think "Maybe a subclass of F would implement P and the reference f actually point to an object of runtime type of the subclass that implements P" but when run, it would throw a
ClassCastException since F and P are not related.
If P was a class, not an interface and even F would not be declared final but it doesn't extend P, it would still not compile. Why? Cause a subclass of F can never subclass P as well, there is no multiple inheritance in
Java Now what would this code do?:
1- Compile Error
2- Runtime Error
3- No Error
[ October 17, 2002: Message edited by: Alfred Kemety ]
[ October 17, 2002: Message edited by: Alfred Kemety ]