Click here to Skip to main content
11,496,146 members (809 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: C#3.0 ASP.NET
difference between an abstract method & virtual method
Explain withe one example
Posted 25-Jan-10 0:14am
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.

Thumbs Up | :thumbsup:
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.
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".
Smile | :)
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:[^]
ProgramFOX at 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)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 RyanDev 230
2 CHill60 163
3 Sascha Lefèvre 145
4 Sergey Alexandrovich Kryukov 124
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100