Consider the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace TestApp
{
interface IMammalClass
{
string Speak();
}
public abstract class absMammalClass : IMammalClass
{
public abstract string Speak();
}
public class basePetClass : absMammalClass
{
public virtual override string Speak()
{
return "Make Noise";
}
}
public class DogClass : basePetClass
{
public override string Speak()
{
return "Bark";
}
}
class Program
{
static void Main(string[] args)
{
DogClass spot = new DogClass();
Console.Out.WriteLine(spot.Speak());
}
}
}
When I attempt to compile the code I get an "override cannot be marked as new or virtual" error with the "public virtual override string Speak()" method. I understand there are ways around it, but I'm wondering what the reasoning is behind C# not allowing virtuals to override abstracts.