Virtual function: Difference between revisions

Content deleted Content added
Fix a grammatical error
Mudshack (talk | contribs)
m Minor edits for clarity
Line 2:
{{more citations needed|date=March 2013}}
{{Polymorphism}}
In [[object-oriented programming]], in languages 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]] forthat whichis [[dynamic dispatch|dispatched dynamically]] is facilitated. ThisVirtual conceptfunctions isare an important part of the (runtime) [[Polymorphism (computer science)|polymorphism]] portion ofin [[object-oriented programming]] (OOP). InThey short,allow afor virtualthe functionexecution defines aof target functionfunctions to be executed, but the targetthat mightwere not beprecisely knownidentified 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>).