Java Program of Bank – Abstract concept

Question:

Banks are supposed to implement their own method that returns back the rate of interest for personal loans. To implement this scenario in SBI and PNB banks they are supposed to extend the Bank class provided by the RBI that has a single abstract method called getRateOfInterest() that returns back an integer.

Develop an automated module wherein the banks SBI and PNB that have their own classes as SBI and PNB that extend from the BANK class and implements the abstract method.

The current rate of interest provided by SBI is 7% and that of PNB is 8 %

Implement the above scenario.

Sample Input and Output

Rate of Interest in SBI is: 7 %

Rate of Interest in PNB is : 8 %

Code:

TestBank.java

public class TestBank{
    public static void main (String[] args) {
    Bank s=new SBI();
    Bank p=new PNB();
    System.out.println("Rate of Interest in SBI is: "+s.getRateOfInterest()+" %");
    System.out.println("Rate of Interest in PNB is: "+p.getRateOfInterest()+" %");
  }
}

SBI.java

public class SBI extends Bank{
    public int getRateOfInterest(){
        return 7;
  }
}

PNG.java

public class PNB extends Bank{
    public int getRateOfInterest(){
        return 8;
    }
}

Bank.java

public abstract class Bank{
    public abstract int getRateOfInterest();
}

Recommended:

  1. Interest Calculator – Interface Concept
  2. Bank – Abstract concept
  3. Inheritance – Account
  4. Contact Details of Hosteller
  5. PF and Salary Calculation
  6. Check for Existence of Customer – equals method
  7. Account Manipulation – Abstract class
  8. Employee Loan Eligibility – Polymorphism

Leave a Comment

Your email address will not be published. Required fields are marked *

x