Create an abstract class 'Bank' with an abstract method 'getBalance'. $100, $150 and $200 are deposited in banks A, B and C respectively. 'BankA', 'BankB' and 'BankC' are subclasses of class 'Bank', each having a method named 'getBalance'. Call this method by creating an object of each of the three classes
#include <iostream>
class Bank {
public:
virtual void getBalance() {}
};
class BankA : public Bank {
public:
void getBalance() override {
std::cout << "Deposited Balance is = $100" << std::endl;
}
};
class BankB : public Bank {
public:
void getBalance() override {
std::cout << "Deposited Balance is = $150" << std::endl;
}
};
int main() {
Bank bank;
bank.getBalance();
BankA bankA;
bankA.getBalance();
BankB bankB;
bankB.getBalance();
return 0;
}
Comments
Leave a comment