Ads

Sunday, December 27, 2020

A boy has his money deposited $1000, $1500 and $2000 in Banks-Bank A, Bank B and Bank C respectively. We have to print the money deposited by him in a particular bank. Create a class "Bank" with a method "getBalance()" which returns 0. Make its three subclasses named "BankA". "BankB" and "BankC" with a method with the same name "getBalance()" which returns the amount deposited in that particular bank. Call the method "getBalance()" by the object of each of the three banks.

 A boy has his money deposited $1000, $1500 and $2000 in Banks-Bank A, Bank B

and Bank C respectively. We have to print the money deposited by him in a

particular bank. Create a class "Bank" with a method "getBalance()" which returns 0. Make its three

subclasses named "BankA".  "BankB" and "BankC" with a method with the same

name "getBalance()" which returns the amount deposited in that particular bank. Call

the method "getBalance()" by the object of each of the three banks.


Source Code..


package bank;

 //@author Java_Programs

public class Bank {

    int amount = 0;

   

    public static void main(String[] args) {

        

        Bank b = new Bank();

        System.out.println("amoutn = " +b.getBalance());

        

        Bank_A ba = new Bank_A();

        System.out.println("amoutn = " +ba.getBalance());

        

        Bank_B bb = new Bank_B();

        System.out.println("amoutn = " +bb.getBalance());

        

        Bank_C bc = new Bank_C();

        System.out.println("amoutn = " +bc.getBalance());

    }

    int getBalance(){

    return 0;

    }

}


class Bank_A extends Bank{

    int getBalance(){

    int deposit = 1000;

    amount = amount + deposit; 

    return amount;

    }

}


class Bank_B extends Bank{

    int getBalance(){

    int deposit = 1500;

    amount = amount + deposit; 

    return amount;

    }

}


class Bank_C extends Bank{    

    int getBalance(){

    int deposit = 2000;

    amount = amount + deposit; 

    return amount;

    }

}





No comments:

Post a Comment