我知道在 c++ 中,继承是“公共”或“私有”或“受保护”,这意味着如果我将 A 类公开继承到 B 类,如下所示
class A
{
public int pub1;
private int prvt1;
protected int proc1;
}
class B : public A
{
//public int pub1;//This variable is because of inheritacne and is internal.
//public int proc1;//This variable is because of inheritacne and is internal.
public int pub2;
private int prvt2;
protected int pro2;
}
即A类的两个变量(pub1,proc1)被继承但访问说明符是公共的。但在C#中如下
class A
{
public int pub1;
private int prvt1;
protected int proc1;
}
class B : A
{
//public int pub1; //This variable is because of inheritacne and is internal.
//protected int proc1;//This variable is because of inheritacne and is internal.
public int pub2;
private int prvt2;
protected int pro2;
}
即 A 类的两个变量 (pub1, proc1) 被继承,但访问说明符与 A 类中的相同。
为什么在.NET 框架中给出这种实现。这有什么优点和缺点?