Click here to Skip to main content
15,063,287 members
Please Sign up or sign in to vote.
1.23/5 (6 votes)
See more:
difference between an abstract method & virtual method
Explain withe one example
Updated 20-Feb-18 17:33pm

GIven how easy this question is to answer on the web, and the way you word this ( as a demand, with a requirement for an example ), I assume this is your homework. Read your texts, and do your own homework.
Abstract method are those which are not defined. Means if your method doesnt have its body it is abstract.

On the other hand, if you have already defined the body and want the classes that derives it can override its member, if they wish, you define it as virtual.

The VB.NET equivalent to these keywords gives a clear knowledge on this :

abstract == MustOverride
virtual == Overridable

I hope you got your answer.

In the C# language documentation (MSDN) you may find all that you need.
For instance, you may find info and examples in "Virtual methods" and "Abstract methods".
An Abstract method must be override in child classes where as virtual method is not compulsory to override.
An abstract method doesn't have implementation detail where as virtual method has it.
only abstract class can haveabstract method, any class can have virtual method
Abstract method are by default empty.
Abstract method must be override in all derived classes.
A class in which Abstract method have must be abstract.
Eg- Abstract void Getdata();
It must be end with (;) in Abstract class.

Virtual method may or may not have body by default.
Virtual method may or may not be override it depends on user.
Eg- Virtual void Getdata() {..........}
There is a complete comparison of virtual vs abstract in the following link:[^]
Thomas Daniels 31-Dec-12 8:19am
This is a question from 2010. Why do you answer to it? The question is solved already.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900