129k views
5 votes
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.

User Tlbrack
by
4.0k points

1 Answer

4 votes

Answer:

abstract class Bank

{

abstract public int getBalance();

}

class BankA extends Bank

{

public int getBalance()

{

return 100;

}

}

class BankB extends Bank

{

public int getBalance()

{

return 150;

}

}

class BankC extends Bank

{

public int getBalance()

{

return 200;

}

}

public class Main

{

public static void main(String[] args)

{

BankA bankA = new BankA();

BankB bankB = new BankB();

BankC bankC = new BankC();

System.out.println("Deposited Balance is = $" + bankA.getBalance());

System.out.println("Deposited Balance is = $" + bankB.getBalance());

System.out.println("Deposited Balance is = $" + bankC.getBalance());

}

}

User Bbrik
by
3.6k points