Static vs. Dynamic Dispatching
When there are multiple method implementations, which one do we decide to use?
C++ uses
- static dispatching when it calls non-virtual methods (uses the function from the static type)
- dynamic dispatching when it calls a Virtual Method (uses the dynamic type of the pointer, implemented using virtual pointer)
Note for Java
Java always uses dynamic dispatching. Except for
final
methods which use static dispatching.