[C#]繼承範例
2008年,老筆記.
using System;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要說明。
/// </summary>
class Class1
{
/// <summary>
/// 應用程式的主入口點。
/// </summary>
[STAThread]
static void Main(string[] args)
{
do
{
int type;
Console.WriteLine("請選擇所要列印的報表規格");
Console.WriteLine("1.標準 2.A4尺寸 3.A3尺寸");
type = int.Parse(Console.ReadLine());
Console.WriteLine("*******************************************************");
switch (type)
{
case 1:
printreport pr = new printreport();
pr.printstart();
break;
case 2:
printA4 pa = new printA4();
pa.printstart();
break;
case 3:
printA3 pa3 = new printA3();
pa3.printstart();
break;
}
} while (true);
}
}
class printreport
{
public printreport()
{
Console.WriteLine("繼承:報表程式啟動......");
}
public virtual void printstart()
{
Console.WriteLine("報表開始列印..");
Console.WriteLine("列印標準尺寸報表...");
Console.WriteLine("工作完成...");
finishedwork("標準");
}
protected void finishedwork(string type)
{
Console.WriteLine("多載:{0}報表列印完成...", type);
Console.WriteLine("多載:清楚佇列工作.....");
}
}
class printA4 : printreport
{
public override void printstart()
{
Console.WriteLine("報表開始列印..");
Console.WriteLine("列印A4尺寸報表...");
Console.WriteLine("工作完成...");
finishedwork("A4");
}
}
class printA3 : printreport
{
public override void printstart()
{
Console.WriteLine("報表開始列印..");
Console.WriteLine("列印A3尺寸報表...");
Console.WriteLine("工作完成...");
finishedwork("A3");
}
}
}