Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
difference between an abstract method & virtual method
Explain withe one example
Posted 25-Jan-10 0:14am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
 
Cheers
Thumbs Up | :thumbsup:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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 | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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() {..........}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

There is a complete comparison of virtual vs abstract in the following link:
 
http://www.dotnetobject.com/Thread-Virtual-and-Abstract[^]
  Permalink  
Comments
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 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
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