Inheritance-Account Program in java

In this post, we will learn Inheritance-Account Program in java Programming language.


Atlas Bank is providing services for various accounts like Savings, Current,Loan for Education ,Vehicle, Home, Personal. As a first step they wanted to automate Savings Account. As a java developer, design the classes as per the given specifications

Create a Account class with the following private attributes:

accntNo – int

accntHolderName – String

accntBalance – double

Provide the appropriate getters/setters

Create another class SavingsAccount which is of type Account with the additional private attributes:

float minBalance

Provide appropriate getters/setters

Override the toString() method in the SavingsAccount class to display the details in the below format


Example: AccountNo:1000-AccountHolderName:Peter-AccountBalance:80000-MinimumBalance:1000

In the TestMain class ,  get the details of Savings Account set the details and print the reference of SavingsAccount

Sample Input/Output:

Enter the AccountNumber: 4000

Enter the Account Holder Name: Rose

Enter the Account Balance: 4000

Enter the Minimum Balance: 500



import java.util.*;
public class TestMain
    public static void main(String[] args)
        Scanner sc=new Scanner(;
        System.out.println("Enter the AccountNumber: ");
        int an=sc.nextInt();
        System.out.println("Enter the Account Holder Name: ");
        System.out.println("Enter the Account Balance: ");
        double ab=sc.nextDouble();
        System.out.println("Enter the Minimum Balance: ");
        float mb=sc.nextFloat();
        SavingsAccount sa=new SavingsAccount();

public class Account
    private int accntNo;
    private String accntHolderName;
    private double accntBalance;
    public void setAccntNo(int accntNo)
    public int getAccntNo()
        return accntNo;
    public void setAccntHolderName(String accntHolderName)
    public String getAccntHolderName()
        return accntHolderName;
    public void setAccntBalance(double accntBalance)
    public double getAccntBalance()
        return accntBalance;

public class SavingsAccount extends Account
    private float minBalance;
    public void setMinBalance(float minBalance)
    public float getMinBalance()
        return minBalance;
    public String toString()
        String str="AccountNo:"+String.valueOf(getAccntNo())+"-AccountHolderName:"+getAccntHolderName()+"-AccountBalance:"
        return str;
  1. Contact Details of Hosteller
  2. PF and Salary Calculation
  3. Check for Existence of Customer – equals method
  4. Account Manipulation – Abstract class
  5. Employee Loan Eligibility – Polymorphism
Sharing Is Caring

Leave a Comment