Virtual function

In object-oriented programming such as is often used in C++ and Object Pascal, a virtual function or virtual method is an inheritable and overridable function or method that is dispatched dynamically. Virtual functions are an important part of (runtime) polymorphism in object-oriented programming (OOP). They allow for the execution of target functions that were not precisely identified at compile time.

Most programming languages, such as JavaScript, PHP and Python, treat all methods as virtual by default[1][2] and do not provide a modifier to change this behavior. However, some languages provide modifiers to prevent methods from being overridden by derived classes (such as the final and private keywords in Java[3] and PHP[4]).

  1. ^ "Polymorphism (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)". docs.oracle.com. Retrieved 2020-07-11.
  2. ^ "9. Classes — Python 3.9.2 documentation". docs.python.org. Retrieved 2021-02-23.
  3. ^ "Writing Final Classes and Methods (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)". docs.oracle.com. Retrieved 2020-07-11.
  4. ^ "PHP: Final Keyword - Manual". www.php.net. Retrieved 2020-07-11.

© MMXXIII Rich X Search. We shall prevail. All rights reserved. Rich X Search