Java Static and Dynamic Binding, Overloading

后端 未结 4 1333
-上瘾入骨i
-上瘾入骨i 2020-12-03 16:38

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         


        
4条回答
  •  抹茶落季
    2020-12-03 17:18

    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 =\

提交回复
热议问题