34,333
edits
Changes
→Creating a Subclass in C#
We now have a new class called ''SavingsAccount'' which inherits all the members of the ''BankAccount'' class and adds some members of its own. In particular we have added a new data member called ''interestRate'' which will store the interest rate paid on the account together with a new method to calculate the monthly interest.
== Passing Aruguments to the Base Class Constructor ==
Of particular significance is the constructor. In the ''BankAccount'' base class we have a constructor which takes the account name and account number as arguments. In the ''SavingsAccount'' subclass we need to accept two additional arguments - the balance and the interest rate. The '': base'' code instructs C# to handle the name and number arguments using the constructor from the base class. The remaining two arguments are then passed to the SavingsAccount constructor.