C# 快速導覽 - abstract 類別







































C# 快速導覽 - abstract 類別






宣告為 abstruct 的類別 (class) 被用作父類別 (superclass) ,這是說 abstruct 類別預設給其他類別繼承,同時不能實作 abstruct 類別中的方法 (method) 。



舉例如下
public abstract class Demo {
public abstract void DoSomething();
}

class Demo2 : Demo {
public override void DoSomething() {
System.Console.WriteLine("There is no spoon.");
}

static void Main() {
Demo2 d = new Demo2();
d.DoSomething();
}
}

/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:class19.cs
功能:示範 C# 程式
作者:張凱慶
時間:西元 2013 年 6 月 */



Demoabstruct 類別,其內的方法也都得宣告為 abstruct
public abstract class Demo {
public abstract void DoSomething();
}



Demo2 繼承 Demo ,使用 override 改寫 Demo 宣告的方法
public override void DoSomething() {
System.Console.WriteLine("There is no spoon.");
}



編譯執行,結果如下



















中英文術語對照
類別class
父類別superclass
方法method



您可以繼續參考

類別




相關目錄

回 C# 快速導覽
回 C# 教材
回首頁



參考資料

Standard ECMA-334 C# Language Specification
msdn: abstract (C# 參考)







沒有留言:




















window.___gcfg = { 'lang': 'zh-TW' };





Popular posts from this blog

迅雷 Thunder 7.9.43.5054 免安裝版 (9.1.41.914 安裝版) - 支援BT下載的萬用 檔案下載工具

qBittorrent 4.1.1 免安裝中文版 - 取代uTorrent的BT下載器

Nhiều đồn đoán cho rằng bộ đồ "phá vỡ quy tắc" của Meghan Markle được lấy cảm hứng từ trang phục của Công nương Diana