Brecht Geeraerts wrote:In my understanding, because the Owl object reference is labeled as Nocturnal, only the method in the Nocturnal interface is accessible (and no longer the method in the Owl class itself). That is why I would have expected this code to output "true", instead of "false".
Seán Kennedy wrote:Would you mind giving me an example of the difference? I always believed the reference was always on the left of the assignment...
Have you seen that the JLS writes about “constant variables”?
The process for choosing methods is exactly as you wrote, including the part about static methods being bound at compile time and not being overridden.
Stephan van Hulst wrote:I'm not sure if they are, it might be dependent on the JVM implementation. I imagine that as a performance enhancement, final methods are indeed called statically rather than through a jump table, but only if you call them through an object reference with a formal type of which it is certain that the method is final.
You can probably figure it out by writing a method that calls a final method and then decompiling the bytecode. If final methods behave like private methods, they will be called using invokespecial. If they behave like other instance methods, they will be called using invokevirtual.
You really shouldn't have to know this for any certifications though.