Please could someone kindly explain why generates a compilation error? I do not think it is because it is NOT overriding the methods of X3. The IDE is not giving me any helpful info to determine the root cause. Thanks in advance for any help that you can give.
The source of this question comes from the Online Udemy Course "Pass the Oracle Certified Associate(OCA): Java SE 8 Programmer I EXAM"
Instructor: Udayan Khattry
Clemonte Johnstone wrote:Its polymorphism as well right
Clemonte Johnstone wrote:as X1 is instantiating X?
No. I suspect this is the part that was confusing Stephan. (And me.) We would not say that X1 instantiates X. We would say that X implements X1 (and X2 and X3). Instantiation is being done by the _39_Question_Intefaces_Inheritance_And_Implementation class in the main() method.
But yes, there's polymorphism here, since the declared type of obj is X1, and yet the actual specific type it references at runtime is an X. And when you call print(), there are multiple implementations to choose from, but because the actual runtime type is X the call resolves to the most specific override, which is found in X3's print() method.