C# 單繼承示例
以下是 C# 中單繼承的示例。在示例中,基類為 Father,宣告如下所示 −
class Father {
public void Display() {
Console.WriteLine("Display");
}
}我們的派生類為 Son,如下面宣告 −
class Son : Father {
public void DisplayOne() {
Console.WriteLine("DisplayOne");
}
}示例
以下是 C# 中實現單繼承的完整示例。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyAplication {
class Demo {
static void Main(string[] args) {
// Father class
Father f = new Father();
f.Display();
// Son class
Son s = new Son();
s.Display();
s.DisplayOne();
Console.ReadKey();
}
class Father {
public void Display() {
Console.WriteLine("Display");
}
}
class Son : Father {
public void DisplayOne() {
Console.WriteLine("DisplayOne");
}
}
}
}輸出
Display Display DisplayOne
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP