Explain why the Java dynamic dispatch algorithm, which looks for the method to invoke for a call obj.foo( ), will never get into an infinite loop.
The dynamic dispatch algorithm throws an runtime error if it not found in invoked class, or its super class and look for till it reaches the Object class
if doesn't find that method signature, it throws runtime error.
Explanation:
If there is a class C which extends to class B, which extends to class A,
if you create an object for class C and invoke a method on it, the dynamic dispatch algorithm looks same method signature on that class
if it's not found, the algorithm look in it's super class, i.e., class B if it was not there, it will check in it's super class till it reaches the Object class
if it's not found in the Object class too, in which case, it will throw runtime error.
The dynamic dispatch algoritm designed to throw an error in the runtime. it's not possible to look for that method in never ending loop.