In Object-Oriented Programming, a virtual function is initially defined in a base class, and can be redefined in derived classes, so that when a virtual function is invoked, the function defined in the receiver's class is executed.
In Object-Oriented Programming, a virtual function is a function that is initially defined in a base class, and can be redefined in derived classes, so that when a virtual function is invoked, the function defined in the receiver's class is executed.
For example, in Java the virtual function toString()
is defined in the root class Object
, and any class may redefine this function to provide a meaningful text representation of an object of that class. (Some classes do not redefine toString()
, using the default implementation instead.)