1classdef Account < handle
2 % A handle class: instances have reference semantics.
3 properties
4 Balance = 0
5 end
6 methods
7 function obj = Account(initial)
8 if nargin > 0
9 obj.Balance = initial;
10 end
11 end
12 function deposit(obj, amount)
13 obj.Balance = obj.Balance + amount;
14 end
15 function withdraw(obj, amount)
16 if amount > obj.Balance
17 error('Account:insufficientFunds', 'Insufficient funds');
18 end
19 obj.Balance = obj.Balance - amount;
20 end
21 end
22end