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

313 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 best solutions below

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