Virtual Method

Noun · Development

Definitions

  1. A method declared in a base class (with the 'virtual' keyword in C++ or C#) that can be overridden by subclasses, with the actual implementation selected at runtime based on the object's dynamic type rather than the variable's declared type. This is the mechanism underlying runtime polymorphism.

    In plain English: A method on a parent class that child classes can replace with their own version, and the computer figures out which version to call while the program is running.

    Example: "Shape::draw() is virtual, so calling draw() on a Shape pointer dispatches to Circle::draw() or Rect::draw() depending on what the object actually is."

Related Terms