Given classes A, B, and C where B extends A and C extends B and where all classes implement the instance method void doIt(). A reference variable is instantiated as "A x = new B();" and then x.doIt() is executed. What version of the doIt() method is actually executed and why? |
|
The version of the doIt() method that’s executed is the one in the B class because of dynamic binding. Dynamic binding basically means that the method implementation that is actually called is determined at run-time, not at compile-time. Hence the term dynamic binding. Although x is of type A, because it references an object of class B, the version of the doIt() method that will be called is the one that exists in B. |

