While the main principle of polymorphism is decoupling \"what from who\" in term of types
, but what confuses me how does method-call mechanism finds out and cal
I think @JBNizet figured out the solution already in the comments (and my guess turned out to be wrong). But since he doesn't post it as an answer, I'll do it:
The main
method isn't supposed to show any dynamic behavior because it is always ever going to call that one single method TestRide.ride(Cycle c)
. There is no other possible method, so nothing to figure out.
The dynamic method call is inside that method TestRide.ride(Cycle c)
. And now that you posted that code, indeed we see a dynamic method dispatch using invokevirtual
. So, after all, no surprises. The dynamic method dispatch is there.