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

298 views Asked by At

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.

3

There are 3 answers

0
pcalcao On BEST ANSWER

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.

0
phs On

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'.

0
irreputable On

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.