Create a class 'Bank' with a function 'getBalance' which returns 0. Make its three subclasses named 'BankA', 'BankB' and 'BankC' with a function with the same name 'getBalance' which returns the amount deposited in that particular bank. Call the function 'getBalance' by the object of each of the three banks.
#include <iostream>
using namespace std;
class Bank {
public:
int getBalance() { return 0; }
};
class BankA : public Bank {
public:
int getBalance() { return 10; }
};
class BankB : public Bank {
public:
int getBalance() { return 20; }
};
class BankC : public Bank {
public:
int getBalance() { return 30; }
};
int main() {
BankA bank1;
BankB bank2;
BankC bank3;
cout << "BankA balance: $" << bank1.getBalance() << endl;
cout << "BankB balance: $" << bank2.getBalance() << endl;
cout << "BankC balance: $" << bank3.getBalance() << endl;
return 0;
}
Comments
Leave a comment