多級繼承的 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..
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP