disadvantages to abstract classes vs virtual c#? code example
Example 1: c# virtual vs abstract
public abstract class E
{
public abstract void AbstractMethod(int i);
public virtual void VirtualMethod(int i)
{
}
}
public class D : E
{
public override void AbstractMethod(int i)
{
}
public override void VirtualMethod(int i)
{
}
}
Example 2: c# abstract class
abstract class Shape
{
public abstract int GetArea();
}
class Square : Shape
{
int side;
public Square(int n) => side = n;
public override int GetArea() => side * side;
static void Main()
{
var sq = new Square(12);
Console.WriteLine($"Area of the square = {sq.GetArea()}");
}
}