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.
Answers
Answered by
2
Program:
#include<iostream>
using namespace std;
class Bank
{
public:
virtual void getBalance() = 0;
};
class BankA : public Bank
{
public:
void getBalance()
{
cout<<"Balance in Bank A is : $100"<<endl;
}
};
class BankB : public Bank
{
public:
void getBalance()
{
cout<<"Balance in Bank B is : $150"<<endl;
}
};
class BankC : public Bank
{
public:
void getBalance()
{
cout<<"Balance in Bank C is : $200"<<endl;
}
};
int main()
{
BankA A;
BankB B;
BankC C;
A.getBalance();
B.getBalance();
C.getBalance();
return 0;
}
Similar questions