| CS 1371 Dept. Presents: |
| CONSTRUCTOR | |
|---|---|
| Definition | A method named the same as the class that consumes initialization data and
produces the initial data structure |
| Example |
function acct =
BankAccount(data)
% BankAccount class constructor.
%
ba = BankAccount(amt) creates a bank account
%
with balance amt
% could also
be a copy contructor:
%
ba = BankAccount( oba ) copies the account oba
if nargin == 0
*%*
acct.balance = 0;
acct = class(acct,'BankAccount');
elseif
isa(data,
'BankAccount')
*^*
acct = data;
else
acct.balance = data;
acct = class(acct,'BankAccount');
end
* %* Provides for being called as just
BankAccount without any data being passed into it.
|