I'm having trouble understanding some concepts of inheritance. I'm doing an assignment where I have to design a basic bank system, and it's asking me to make a class derived of a base class. Here's the exact question:
c. Every bank offers a savings account. Derive the class savingsAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a savings account typically receives interest, makes deposits, and withdraws money. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, post interest, withdraw (override the method of the base class), and print account information. Add appropriate constructors.
Now, I may be understanding the instructions wrong, but am I supposed to be using the functions from the base class to modify members of the derived class? If so, how do I do that? Here's my code so far, but when I create a new savingsAccount object, it sets the default values from the constructor of the bankAccount class. I haven't tested the other savingsAccount functions, but I have a feeling it's the same problem. Here's the code:
You can't have the base's methods modify members of the derived class. That doesn't make sense. I'm not sure I understand what you are asking.
When derived classes are constructed, the base class's constructor is called first. This is the expected behavior; the base class should initialize it's values with it's constructor, and the derived class should initialize it's own.
I think I was confused because of the wording of the problem. It's asking me to override the method of the base class, meaning I need to put a call to the base class function in the definition of the derived class' function, right? So I thought the base class' function had to modify the balance member of the savingsAccount object when it was called through the savingsAccount object.