Virtual function: Difference between revisions

Content deleted Content added
mNo edit summary
Line 3:
In [[object-oriented programming]], in languages such as [[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]] for which [[dynamic dispatch]] is facilitated. This concept is an important part of the (runtime) [[Polymorphism (computer science)|polymorphism]] portion of [[object-oriented programming]] (OOP). In short, a virtual function defines a target function to be executed, but the target might not be known at compile time.
 
Most programming languages, such as [[Java (programming language)|Java]], [[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> and do not provide a modifier to change this behavior. However, some of themlanguages provide modifiers to avoidprevent methods tofrom bebeing overridden by derived classes (as the ''final'' keyword 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>).
 
== Purpose ==