多級繼承的 C# 示例
當一個派生類從另一個派生類中形成時,就會發生多級繼承。
在 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..
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP