衍生類別建構子隱式呼叫基底類別建構子,按類別階層順序執行。輸出範例:
Value of count in base class = 11
Value of count in derived class = 110
abstract 方法/屬性(無實作)override 所有抽象成員(除非衍生類也標記 abstract)
using System;
public abstract class Employee
{
public abstract void show();
}
public class Manager : Employee
{
string name;
public Manager(string name) => this.name = name;
public override void show() => Console.WriteLine("Name: " + name);
}
public class CreateManager
{
public static void Main(string[] args)
{
Employee temp = new Manager("John Chapman");
temp.show(); // 呼叫 Manager 實作
}
}
public
public interface IMethodInterface
{
void MethodA();
int MethodB(float p1, bool p2);
int ReadOnlyProperty { get; } // 唯讀屬性
}
屬性僅用 get/set 指示存取性。