Using C# for a while, I've just got curious about overriding abstract methods. I'm NOT asking "Why we have to override every abstract method?", but asking "Why we use override
keyword on implementing abstract method?".
Abstract class were really useful when I had to provide the basic functionality of classes. Since Unity doesn't support C# 8.0 yet, the only choice to provide default method was to make abstract classes :(
public interface ISomething
{
void DoSomething();
}
public class A : ISomething
{
public void DoSomething() { }
}
// ----------------------------------
public abstract class Something
{
public abstract void DoSomething();
{
public class B : Something
{
public override void DoSomething() { } // WHY override to only this??
}
What I thought to be weird is, there is literally nothing to override in abstract method since there is no function body, just like interface method. Then why I should write override
keyword? Is there any purpose for it? Or Was there any inevitable reason to do so?