Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Virtual function
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Inheritable and overridable function or method for which dynamic dispatch is facilitated}} {{more citations needed|date=March 2013}} {{Polymorphism}} In [[object-oriented programming]] such as is often used in [[C++]] and [[Object Pascal]], a '''virtual function''' or '''virtual method''' is an inheritable and [[Method overriding (programming)|overridable]] [[function (computer science)|function]] or [[method (computer science)|method]] that is [[dynamic dispatch|dispatched dynamically]]. Virtual functions are an important part of (runtime) [[Polymorphism (computer science)|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 (programming language)|Python]], treat all methods as virtual by default<ref>{{Cite web|title=Polymorphism (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)|url=https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html|access-date=2020-07-11|website=docs.oracle.com}}</ref><ref>{{Cite web|title=9. Classes — Python 3.9.2 documentation|url=https://docs.python.org/3/tutorial/classes.html|access-date=2021-02-23|website=docs.python.org}}</ref> 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 (programming language)|Java]]<ref>{{Cite web|title=Writing Final Classes and Methods (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)|url=https://docs.oracle.com/javase/tutorial/java/IandI/final.html|access-date=2020-07-11|website=docs.oracle.com}}</ref> and [[PHP]]<ref>{{Cite web|title=PHP: Final Keyword - Manual|url=https://www.php.net/manual/en/language.oop5.final.php|access-date=2020-07-11|website=www.php.net}}</ref>).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)