Techopedia Explains Virtual Method
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.
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.
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.
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.
- Mainframes Aren't Dead
- AI in the Army: How Virtual Assistants Will Impact US Military Ranks
- How Cloud Computing is Changing Cybersecurity
- Immersive Graphical Displays of Information: How Mixed Reality Technology is Changing the Game
- Virtual Training: Paving Advanced Education's Future
- Considering a VPN? Make the Right Choice for Your Needs