Inheritance
- A new table can be built that inherits from the Account table
- The new table will have the same __index function in its metatable
- So it will inherits the functions and variables of Account
An example of inheritance Put this code and the prior code into files and try them They can also be found in the sample files for the course
local account = require "objectOriented.classAccount" SpecialAccount = Account:new() function SpecialAccount:withdraw(v) if v - self.balance >= self:getLimit() then error "insufficient funds" end self.balance = self.balance - v end function SpecialAccount:getLimit() return self.limit or 0 end newAccount = SpecialAccount:new{limit=1000.00} newAccount:deposit(100.00) newAccount:withdraw(200.00) newAccount:print() local limit = newAccount:getLimit() print("Account limit is " .. limit)