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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajeev KumarPosted Jul 10, 2023, 7:53 AM
Abstract Method
Virtual Method
Deepak MiddhaPosted Nov 3, 2012, 2:38 AM
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"
Nehru KandasamyPosted Nov 3, 2012, 12:51 AM
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