In java, if a method NOT inherited by any subclass is called, whether dynamic binding or static binding is used?

StackOverflow https://stackoverflow.com/questions/7761226

문제

In java, if a method NOT inherited by any subclass is called, whether dynamic binding or static binding is used?

I know it won't make any difference to the output in this particular case, but just wanted know this.

도움이 되었습니까?

해결책

Instance method calls in Java always use dynamic binding. Static methods and direct access to private members use static binding.

In length: http://geekexplains.blogspot.com/2008/06/dynamic-binding-vs-static-binding-in.html

This article explains it pretty good.

다른 팁

Unless the class or method is marked final, it could be overridden by new types introduced at runtime by a class loader. In this sense they are still 'dynamic'.

At runtime, JVM knows all classes loaded, and whether a method is overridden; the final modifier on methods doesn't matter to JVM.

With that knowledge, JVM will optimize calls to methods that are not overridden; the binding is "static" in that sense.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top