[英]C# abstract class desgin, is that possible put a constuctor in abstract class and call base to access them
I was practicing c# abstract class and inheritance, but I was wondering if derived classes could access the constructor by calling the base我在练习 c# abstract class 和 inheritance,但我想知道派生类是否可以通过调用基类来访问构造函数
public abstract class A
{
protected bool value_A;
protected int value_B;
public A(int input)
{
A = true;
B = false;
}
public abstract int function_B();
}
}
public class childA : A
{
public childA (int input):base(input)
{
}
public override int function_B()
{
//do smth
}
}
public class childB : A
{
public childB(int input):base(input)
{
}
public override int function_B()
{
//do something different
}
public void functionC(int input)
{
}
}
I was confused if I should use this abstract class design or just go ez by using inheritance -> declare a virtual function in class A. I was confused if I should use this abstract class design or just go ez by using inheritance -> declare a virtual function in class A.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.