【发布时间】:2015-02-10 06:34:28
【问题描述】:
我只是想了解以下是否可行。
我有 customer、specialCustomer 和 goldCustomer 类。 Special 继承自 Customer,GoldCustomer 继承自 SpecialCustomer。
如何从 GoldCustomer 访问 Customer 类的 Add() 实现?使用 base.Add() 只调用直接父级的 Add()
public class Customer
{
public virtual void add()
{
Console.WriteLine("Base Add");
}
}
public class SpecialCustomer: Customer
{
public override void add()
{
Console.WriteLine("SPL CUST Add");
}
}
public class GoldCustomer : SpecialCustomer
{
public new void add()
{
base.add();// cals the immediate parent.
//How to call the method on Customer base class(Parent's parent)
Console.WriteLine(" chid GOLD CUST Add");
}
}
【问题讨论】:
标签: c# inheritance