C# 多级继承示例
csharpserver side programmingprogramming更新于 2025/9/24 15:55:00
当一个派生类由另一个派生类形成时,就会发生多级继承。
祖父、父亲和儿子是 C# 中表示多级继承的完美示例 −

示例
以下是说明 C# 中多级继承用法的示例。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class Son : Father {
public void DisplayTwo() {
Console.WriteLine("Son.. ");
}
static void Main(string[] args) {
Son s = new Son();
s.Display();
s.DisplayOne();
s.DisplayTwo();
Console.Read();
}
}
class Grandfather {
public void Display() {
Console.WriteLine("Grandfather...");
}
}
class Father : Grandfather {
public void DisplayOne() {
Console.WriteLine("Father...");
}
}
}
输出
Grandfather... Father... Son..

