I am practicing for a test and I came across this exercise about overloading and static and dynamic binding. The output of the following code is asked:
class
So this is a super confusing and awful example of something you should never do. The declared type of the variables matters for what signature methods have. So Larry
doesn't have method that accepts a Curly
, so the compiler considers the argument a Larry
. But it gets dispatched to Curly
's version of the method.
So yeah, never ever do this =\