You're trying to call method func1
on class A
, where A
does not define it? You can't. You can make Func1
abstract within A
if you want to do that.
abstract class A
{
public abstract Func1();
}
class B : A
{
public override Func1()
{
MessageBox.Show("Hello World");
}
}
class C : A
{
public override Func1()
{
MessageBox.Show("Goodbye World");
}
}
The fact that Func1
is abstract means that you can't instantiate A
directly, but you can instantiate B
.
var listOfA = new List<A>();
listOfA.Add(new B());
listOfA.Add(new C());
listOfA[0].Func1(); // hello world
listOfA[1].Func1(); // goodbye world
You could make Func1
defined as virtual in A
instead of setting it as abstract, but I recommend you do not because this will introduce a reversed Refused Bequest design smell.