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
abstract class Bank {
abstract int getBalance();
}
class BankA extends Bank {
private int balance;
void deposit(int money) {
balance += money;
}
@Override
int getBalance() {
return balance;
}
}
class BankB extends Bank {
private int balance;
void deposit(int money) {
balance += money;
}
@Override
int getBalance() {
return balance;
}
}
class BankC extends Bank {
private int balance;
void deposit(int money) {
balance += money;
}
@Override
int getBalance() {
return balance;
}
}
public class Main {
public static void main(String[] args) {
BankA bankA = new BankA();
BankB bankB = new BankB();
BankC bankC = new BankC();
bankA. deposit(100);
bankB. deposit(150);
bankC. deposit(200);
System.out.println("Balance of Bank A = $"+a.getBalance());
System.out.println("Balance of Bank B = $"+b.getBalance());
System.out.println("Balance of Bank C = $"+c.getBalance());
}
}
Answer:
abstract class Bank{
public abstract void getBalance();
}
class BankA extends Bank{
public void getBalance(){ System.out.println("Deposited Balance is = $100"); }
}
//Written and logic by Avtar Singh (Singha2k2)
class BankB extends Bank{
public void getBalance(){ System.out.println("Deposited Balance is = $150"); }
}
class BankC extends Bank{
public void getBalance(){ System.out.println("Deposited Balance is = $200"); }
}
class calculateBalance{
public static void main(String[] args){
BankA Balance1 = new BankA();
Balance1.getBalance();
BankB Balance2 = new BankB();
Balance2.getBalance();
BankC Balance3 = new BankC();
Balance3.getBalance();
}
}
Explanation:
Corrrect Answer