小编h0a*_*0ax的帖子

如何从子类中的方法调用子类中覆盖的父方法?

我想调用 FamilyCar 方法 Move()。如果 FamilyCar 是 LandVehicle,我想同时调用 LandVehicle Move() 方法。我正在寻找非常基本的方法来做到这一点。

基类

class LandVehicle : Vehicle
    {
        public override string Move()
        {
            return "Move on the wheels";
        }
    }
Run Code Online (Sandbox Code Playgroud)

子类

class FamilyCar : LandVehicle
{
        public override string Move()
        {
            return "Pip pip!";
        }
}
Run Code Online (Sandbox Code Playgroud)

c# oop methods method-call

1
推荐指数
1
解决办法
57
查看次数

标签 统计

c# ×1

method-call ×1

methods ×1

oop ×1