I suspect what you are looking for is:
public abstract class A
{
public abstract int add(int n1, int n2);
public abstract int add(int n1, int n2, int n3);
}
public abstract class B : A
{
public override int add(int n1, int n2)
{
return (n1 + n2);
}
}
public class C : B
{
public override int add(int n1, int n2, int n3)
{
return (n1 + n2 + n3);
}
}
Ultimately, C (which is not declared as abstract
) needs to provide an implementation for both add
variants (which it does by implementing one of them ‘directly’ and one of them via B).
If you want C to not inherit from B, but only provide one implementation – alas that is not possible if C is not abstract
.
1
solved C# Abstract class two methods same name but with different inputs [closed]