In: Computer Science
SavingsAccount is a derived class from Account. SavingsAccount has inherited member variables & functions
and ordinarily-defined member variables & functions.
• The member variable balance in base class Account is protected, which means:
– balance is NOT publicly accessible outside the class, but it is accessible in the derived classes.
– if balance was declared as private, then SavingsAccount member functions could not access it.
• When using objects of type SavingsAccount, the inherited and derived members are treated exactly the same
and are not distinguishable.
• CheckingAccount is also a derived class from base class Account.
• TimeAccount is derived from SavingsAccount. SavingsAccount is its base class and Account is its indirect
base class.
Constructors of a derived class call the base class constructor immediately, before doing ANYTHING else.
The only thing you can control is which constructor is called and what the arguments will be. Thus when
a TimeAccount is created 3 constructors are called: the Account constructor, then the SavingsAccount constructor, and then finally the TimeAccount constructor.
• The reverse is true for destructors: derived class constructors do their jobs first and then base class destructors
are called at the, automatically. Note: destructors for classes which have derived classes must be marked virtual for this chain of calls to happen.