static void Main(string[] args)
{
Console.WriteLine("学生甲抄的试卷:");
TestPaper A = new TestPaperA();
A.TestQuestion1();
A.TestQuestion2();
A.TestQuestion3();
Console.WriteLine("学生乙抄的试卷:");
TestPaper B = new TestPaperB();
B.TestQuestion1();
B.TestQuestion2();
B.TestQuestion3();
Console.ReadKey();
}
}
abstract class TestPaper //此处原书是普通类,此处改为抽象类,从而而不用实现虚方法
{
public void TestQuestion1()
{
Console.WriteLine("1+1,A.2 B.3 C.4. D.1");
Console.WriteLine("答案:" + Answer1());
}
protected abstract string Answer1();
public void TestQuestion2()
{
Console.WriteLine("月有阴晴圆__ A.方 B.窄 C.缺 D.美");
Console.WriteLine("答案:" + Answer2());
}
protected abstract string Answer2();
public virtual void TestQuestion3()
{
Console.WriteLine("《机动车安全运行技术条件》的简称是 A.GB18565 B.GB7258 C.GB800 D.GB400");
Console.WriteLine("答案:" + Answer3());
}
protected abstract string Answer3();
}
class TestPaperA : TestPaper
{
protected override string Answer1()
{
return "A";
}
protected override string Answer2()
{
return "B";
}
protected override string Answer3()
{
return "C";
}
}
class TestPaperB : TestPaper
{
protected override string Answer1()
{
return "C";
}
protected override string Answer2()
{
return "B";
}
protected override string Answer3()
{
return "A";
}
}