TestPaper = {}
function TestPaper:new(o)
o = o or {}
setmetatable(o,self)
self.__index = self
return o;
end
-- 稳定
function TestPaper:Run()
self:TestQuestion1() --稳定
self:TestQuestion2() --稳定
self:TestQuestion3() --包含变化(子类实现)
end
function TestPaper:TestQuestion1()
print("孙悟空的师弟是谁?")
print("A 猪七戒 B 猪八戒 C 猪九戒")
print("答案是:B")
end
function TestPaper:TestQuestion2()
print("猪八戒的师弟是谁?")
print("A 沙和尚 B 沙道士 C 沙井盖")
print("答案是:A")
end
function TestPaper:TestQuestion3()
print("沙和尚的大师兄是谁?")
print("A 孙中山 B 孙权 C 孙悟空")
print("答案是:"..self:Answer3())
end
-- 子类实现答案3
GroupATestPaper = TestPaper:new()
function GroupATestPaper:Answer3()
return "A"
end
GroupATestPaper:Run()