Then why two different concepts?
How to decide which one to use in what situation?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Nehru Kandasamy14 reputationPosted Nov 2, 2012, 8:51 PM EDT
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.
If you Need any Referrence:
http://www.dotnetfunda.com/forums/thread7477-difference-between-abstract-and-virtual-method.aspx
Deepak MiddhaRank #214 · 11.3K reputationPosted Nov 2, 2012, 10:38 PM EDT
Difference b/w Abstract and virtual method:
here I am giving example of both:
Abstract Method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
abc1 obj = new abc1();
int x= obj.ss(5, 4);
Console.WriteLine("the result is:" + x);// we cant use our orignel method.
Console.ReadKey();
}
}
abstract class abc
{
public abstract int ss(int x,int y);
}
class abc1 : abc
{
public override int ss(int x, int y)
{
return x + y;
}
}
}
Output:
Virtual Method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vrtualmethod
{
class Program
{
static void Main(string[] args)
{
abcd obj1 = new abcd();
int y = obj1.dd(4, 5);
Console.WriteLine("output of orignel method=" + y);//here we can use our Orignel method.
bcd obj = new bcd();
int x= obj.dd(4,5);
Console.WriteLine("Output of Overrided mehod:"+x);
Console.ReadKey();
}
}
class abcd
{
public virtual int dd(int x, int y)
{
return x + y;
}
}
class bcd : abcd
{
public override int dd(int x, int y)
{
return x * y;
}
}
}
Output:
If this post is useful then mark it as "Accepted Answer"
Rajeev KumarRank #1,334 · 1.3K reputationPosted Jul 10, 2023, 3:53 AM EDT
Abstract Method
Virtual Method