local IP = 3.1415926
base = {area = 0}
base.new = function(self,o,r)
- o = o or {}
| setmetatable(o, {__index = self})
| r = r or 0
| self.area = r*r*IP
| return o
end
base.printArea = function(self)
- print("area = '%f'", self.area)
end
derive = base:new()
derive.new = function(self, o, length, width)
o = o or base:new()
setmetatable(o, {__index = self})
length = length or 0
hail = hail or 0
self.area = length * width
return o
end
derive.printArea = function(self)
- print("area = '%f'", self.area)
end
local model1 = derive:new(nil, 5, 4)
model1:printArea()
lua继承实例
最新推荐文章于 2024-07-26 01:03:45 发布