Below code gives me compiler error :
'Rextester.Derived.foo()': cannot change access modifiers when overriding 'public' inherited member 'Rextester.Base.foo()'
Why can't derive class keep the implementation of overridden function private to itself ? This is allowed in Cpp.
One use case i find is to force developer to use Base classes. In working with large code bases, i think this is useful.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
class Base
{
public virtual string foo()
{
return "hi base";
}
}
class Derived : Base
{
protected override string foo()
{
return "bye derived";
}
}
public class Program
{
public static void Main(string[] args)
{
Base b = new Derived();
//Your code goes here
Console.WriteLine(b.foo());
}
}
}
Code link : https://rextester.com/LBQO45364