C# › OOP

How do virtual method tables enable polymorphism, and what is the cost?

Advanced

Answer

Each type with virtual members has a method table; a virtual call looks up the actual implementation at run time via the object's type. It costs an indirection versus a direct/sealed call.
Shape s = new Square(3);
double a = s.Area(); // resolved to Square.Area at run time
Real-world example Hot loops sometimes seal types or use generics to let the JIT remove virtual dispatch.