{"id":10437,"date":"2011-12-28T12:38:24","date_gmt":"2011-12-28T12:38:24","guid":{"rendered":"https:\/\/www.techopedia.com\/definition\/virtual-method\/"},"modified":"2011-12-28T12:45:10","modified_gmt":"2011-12-28T12:45:10","slug":"virtual-method","status":"publish","type":"definition","link":"https:\/\/www.techopedia.com\/definition\/24299\/virtual-method","title":{"rendered":"Virtual Method"},"content":{"rendered":"
A virtual method is a declared class method that allows overriding by a method with the same derived class signature. Virtual methods are tools used to implement the polymorphism feature of an object-oriented language, such as C#. When a virtual object instance method is invoked, the method to be called is determined based on the object’s runtime type, which is usually that of the most derived class.<\/p>\n
A virtual method is used to override specified base class implementation when a runtime object is of the derived type. Thus, virtual methods facilitate the consistent functionality of a related object set.<\/p>\n
An example of a virtual method implementation is classes Manager and Clerk, derived from the base class Employee with a CalculateSalary virtual method, which may be overridden in derived classes with the necessary logic for the appropriate type. A list of Employee type objects may be called at runtime to calculate a salary – without knowing the specific implementation type.<\/p>\n
Virtual method implementation differs in programming languages like C++, Java, C# and Visual Basic .NET. In Java, all non-static methods are virtual by default, with the exception of methods that are private or marked with the keyword final. C# requires the keyword virtual for virtual methods, with the exception of private, static and abstract methods, and the keyword override for overriding the derived class method.<\/p>\n
A pure virtual method is a virtual method that mandates a derived class to implement a method and does not allow instantiation of the base class, or abstract class. <\/p>\n","protected":false},"excerpt":{"rendered":"
What Does Virtual Method Mean? A virtual method is a declared class method that allows overriding by a method with the same derived class signature. Virtual methods are tools used to implement the polymorphism feature of an object-oriented language, such as C#. When a virtual object instance method is invoked, the method to be called […]<\/p>\n","protected":false},"author":7813,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"_lmt_disableupdate":"","_lmt_disable":"","om_disable_all_campaigns":false,"footnotes":""},"definitioncat":[224,244,216],"class_list":["post-10437","definition","type-definition","status-publish","format-standard","hentry","definitioncat-containers-virtualization","definitioncat-programming-languages","definitioncat-software-development"],"acf":[],"yoast_head":"\n