Both (abstract methods and virtual methods) offer similar functionality – when should you use virtual methods and when should you use abstract methods?

Base Functionality Driven

If you want a base behavior as the default behavior and allow child behavior to override it – then use virtual methods. If you want to leave the base behavior un-defined – and have child classes take on full responsibility for implementing that behavior – use abstract methods (this comes with the drawback of forcing your entire class to be abstract).

Performance Driven

Virtual methods have slower performance.

Abstract methods are virtual by default

Abstract methods are by default virtual – since they MUST be overridden.

Containing Classes

A class that contains an abstract method (even a single one) – has to be marked as abstract. However, if a class contains virtual methods, it can be concrete.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.