ISC Practicals and Theory - Account to Savings/Current (OOP)
Updated 21 Oct 2026
A bank has different kinds of accounts that share common details (name, account number, balance) but follow different rules. This version uses parameterised constructors that pass the common details up with super(...), and method overriding: the derived classes Savings and Current redefine methods of the base class Account, and the driver calls them through a base class reference, so Java picks the right version at run time.
Definition
Inheritance lets a derived class (written with extends) acquire the members of a base class. A derived class constructor calls the base class constructor with super(...), which must be its first statement. Method overriding (redefinition) means a derived class defines a method with the same name and parameters as the base class. Polymorphism with dynamic binding means that when a base class reference Account ob holds a Savings or Current object, the call ob.display() runs the version belonging to the object, not to the reference type.
The rules below are a sample set for this program. An ISC question states its own rules, so when you answer one, use the question's rules in place of these.
- Validation: opening balance must not be negative; deposit and withdrawal amounts must be greater than 0; otherwise the program prints
INVALID INPUT. - Savings: one year's simple interest, $\text{interest} = \dfrac{\text{balance} \times \text{rate}}{100}$, is added once, after the deposit and the withdrawal. The rate is typed by the user and must be greater than 0.
- Withdrawal (base rule): rejected if the amount is more than the balance, since the balance would go below 0. A withdrawal equal to the balance is allowed.
- Current: the minimum balance and the service charge are typed by the user. The base rule above applies; after a successful withdrawal, if the balance is less than the minimum balance, the service charge is deducted once. A balance exactly equal to the minimum is not charged. The charge is deducted even if the balance becomes negative.
For example, a Current account with balance 5000, deposit 1000, withdrawal 5500, minimum balance 1000 and charge 50: the balance becomes $5000 + 1000 - 5500 = 500$, which is less than 1000, so 50 is deducted and the final balance is 450.
Algorithm
main(in the driver classTest) reads the account type, name, account number, opening balance, deposit amount and withdrawal amount. If the type is notSorC, or the balance is negative or an amount is not positive, it printsINVALID INPUTand stops.- For
S, it reads the rate (must be above 0) and executesob = new Savings(name, accNo, bal, rate). ForC, it reads the minimum balance and the service charge (neither negative) and executesob = new Current(name, accNo, bal, minBal, charge).obis declared asAccount. - The derived constructor calls
super(n, a, b), which setsname,accNoandbalance, and then sets its own data member(s). maincallsob.deposit(dep), which adds the amount tobalance.maincallsob.withdraw(wd):- for
Savingsthis is theAccountmethod: ifamt > balanceit prints the rejection message and returnsfalse; otherwise it subtractsamtand returnstrue; - for
Currentthe overridden method callssuper.withdraw(amt)and, if it returnedtrueandbalance < minBal, subtractscharge.
- for
maincallsob.update(). InAccountit does nothing;Savingsoverrides it to calculate and add the interest.maincallsob.display(). The overridden versions callsuper.display()and then print the details of their own type.
Program
Account has the common data and the methods deposit(), withdraw(), update() and display(). Savings overrides update() and display(); Current overrides withdraw() and display().
import java.util.Scanner;
/**
* Base class Account: holds the details common to every bank account.
*/
class Account
{
String name; // name of the account holder
long accNo; // account number
double balance; // current balance in rupees
/**
* Parameterised constructor.
* @param n name of the holder
* @param a account number
* @param b opening balance
*/
Account(String n, long a, double b)
{
name = n;
accNo = a;
balance = b;
}
/**
* Adds an amount to the balance.
* @param amt amount to be deposited
*/
void deposit(double amt)
{
balance = balance + amt;
System.out.println("Deposit of " + amt + " done. Balance: " + balance);
}
/**
* Withdraws an amount; rejected if it exceeds the balance (overridden in Current).
* @param amt amount to be withdrawn
* @return true if the withdrawal was done, false if it was rejected
*/
boolean withdraw(double amt)
{
if (amt > balance)
{
System.out.println("Withdrawal rejected: insufficient balance.");
return false;
}
balance = balance - amt;
System.out.println("Withdrawal of " + amt + " done. Balance: " + balance);
return true;
}
/** End-of-period processing; a plain Account has none (overridden in Savings). */
void update()
{
}
/** Prints the details common to every account (overridden in the derived classes). */
void display()
{
System.out.println("Name: " + name);
System.out.println("Account number: " + accNo);
System.out.println("Balance: " + balance);
}
}
/**
* Derived class Savings: an Account that earns interest.
*/
class Savings extends Account
{
double rate; // rate of interest, per cent per year
/**
* Parameterised constructor; passes the common details to the base class with super(...).
* @param n name of the holder
* @param a account number
* @param b opening balance
* @param r rate of interest in per cent
*/
Savings(String n, long a, double b, double r)
{
super(n, a, b);
rate = r;
}
/** Overrides update(): adds one year's simple interest on the current balance. */
void update()
{
double interest = balance * rate / 100; // interest for one year
balance = balance + interest;
System.out.println("Interest of " + interest + " added. Balance: " + balance);
}
/** Overrides display(): common details plus the Savings details. */
void display()
{
super.display();
System.out.println("Account type: Savings");
System.out.println("Rate of interest: " + rate + "%");
}
}
/**
* Derived class Current: an Account with a minimum balance and a service charge.
*/
class Current extends Account
{
double minBal; // minimum balance to be maintained
double charge; // service charge deducted when balance is below minBal
/**
* Parameterised constructor; passes the common details to the base class with super(...).
* @param n name of the holder
* @param a account number
* @param b opening balance
* @param m minimum balance
* @param c service charge
*/
Current(String n, long a, double b, double m, double c)
{
super(n, a, b);
minBal = m;
charge = c;
}
/**
* Overrides withdraw(): uses the base class rule, then charges if balance falls below minBal.
* @param amt amount to be withdrawn
* @return true if the withdrawal was done, false if it was rejected
*/
boolean withdraw(double amt)
{
boolean done = super.withdraw(amt); // base class does the withdrawal or rejects it
if (done && balance < minBal)
{
balance = balance - charge;
System.out.println("Service charge of " + charge + " deducted. Balance: " + balance);
}
return done;
}
/** Overrides display(): common details plus the Current details. */
void display()
{
super.display();
System.out.println("Account type: Current");
System.out.println("Minimum balance: " + minBal);
System.out.println("Service charge: " + charge);
}
}
/**
* Driver class: reads the details, then uses an Account reference for a Savings or Current object.
*/
public class Test
{
/** Entry point: reads the input, creates the object and calls the overridden methods through ob. */
public static void main(String args[])
{
Scanner sc = new Scanner(System.in); // reads the typed input
System.out.print("Enter account type (S for Savings, C for Current): ");
String t = sc.next(); // type typed by the user
sc.nextLine(); // discard the rest of the line before reading the name
char type = Character.toUpperCase(t.charAt(0));
if (type != 'S' && type != 'C')
{
System.out.println("INVALID INPUT");
return;
}
System.out.print("Enter name: ");
String name = sc.nextLine(); // name of the holder
System.out.print("Enter account number: ");
long accNo = sc.nextLong(); // account number
System.out.print("Enter opening balance: ");
double bal = sc.nextDouble(); // opening balance
System.out.print("Enter deposit amount: ");
double dep = sc.nextDouble(); // amount to deposit
System.out.print("Enter withdrawal amount: ");
double wd = sc.nextDouble(); // amount to withdraw
if (bal < 0 || dep <= 0 || wd <= 0)
{
System.out.println("INVALID INPUT");
return;
}
Account ob; // base class reference, holds a derived class object
if (type == 'S')
{
System.out.print("Enter rate of interest (%): ");
double rate = sc.nextDouble(); // rate of interest
if (rate <= 0)
{
System.out.println("INVALID INPUT");
return;
}
ob = new Savings(name, accNo, bal, rate);
}
else
{
System.out.print("Enter minimum balance: ");
double minBal = sc.nextDouble(); // minimum balance
System.out.print("Enter service charge: ");
double charge = sc.nextDouble(); // service charge
if (minBal < 0 || charge < 0)
{
System.out.println("INVALID INPUT");
return;
}
ob = new Current(name, accNo, bal, minBal, charge);
}
ob.deposit(dep);
ob.withdraw(wd);
ob.update();
ob.display();
}
}Variable description table
| Variable | Data Type | Purpose |
|---|---|---|
name | String | Data member of Account: name of the account holder |
accNo | long | Data member of Account: account number |
balance | double | Data member of Account: current balance |
rate | double | Data member of Savings: rate of interest in per cent per year; also a local variable in main holding the typed rate |
minBal | double | Data member of Current: minimum balance to be maintained; also a local variable in main holding the typed value |
charge | double | Data member of Current: service charge; also a local variable in main holding the typed value |
n | String | Constructor parameter: name of the holder |
a | long | Constructor parameter: account number |
b | double | Constructor parameter: opening balance |
r | double | Parameter of the Savings constructor: rate of interest |
m | double | Parameter of the Current constructor: minimum balance |
c | double | Parameter of the Current constructor: service charge |
amt | double | Parameter of deposit() and withdraw(): the amount |
interest | double | Local variable in Savings.update(): interest for one year |
done | boolean | Local variable in Current.withdraw(): whether the base class withdrawal succeeded |
sc | Scanner | Local variable in main: reads the typed input |
t | String | Local variable in main: the account type text typed by the user |
type | char | Local variable in main: first letter of t in capitals, S or C |
accNo (in main) | long | Local variable in main: account number typed by the user |
bal | double | Local variable in main: opening balance typed by the user |
dep | double | Local variable in main: deposit amount |
wd | double | Local variable in main: withdrawal amount |
ob | Account | Base class reference in main, holding a Savings or a Current object |
args | String[] | Command-line arguments of main (not used) |
Sample input and output
Sample 1
Enter account type (S for Savings, C for Current): S
Enter name: Asha Rao
Enter account number: 1001
Enter opening balance: 5000
Enter deposit amount: 1000
Enter withdrawal amount: 2000
Enter rate of interest (%): 4
Deposit of 1000.0 done. Balance: 6000.0
Withdrawal of 2000.0 done. Balance: 4000.0
Interest of 160.0 added. Balance: 4160.0
Name: Asha Rao
Account number: 1001
Balance: 4160.0
Account type: Savings
Rate of interest: 4.0%Sample 2
Enter account type (S for Savings, C for Current): S
Enter name: Meena Iyer
Enter account number: 3003
Enter opening balance: 1000
Enter deposit amount: 500
Enter withdrawal amount: 2000
Enter rate of interest (%): 5
Deposit of 500.0 done. Balance: 1500.0
Withdrawal rejected: insufficient balance.
Interest of 75.0 added. Balance: 1575.0
Name: Meena Iyer
Account number: 3003
Balance: 1575.0
Account type: Savings
Rate of interest: 5.0%Sample 3
Enter account type (S for Savings, C for Current): C
Enter name: Ravi Kumar
Enter account number: 2002
Enter opening balance: 5000
Enter deposit amount: 1000
Enter withdrawal amount: 5500
Enter minimum balance: 1000
Enter service charge: 50
Deposit of 1000.0 done. Balance: 6000.0
Withdrawal of 5500.0 done. Balance: 500.0
Service charge of 50.0 deducted. Balance: 450.0
Name: Ravi Kumar
Account number: 2002
Balance: 450.0
Account type: Current
Minimum balance: 1000.0
Service charge: 50.0Sample 4
Enter account type (S for Savings, C for Current): C
Enter name: Om Jha
Enter account number: 6006
Enter opening balance: 2000
Enter deposit amount: 500
Enter withdrawal amount: 3000
Enter minimum balance: 1000
Enter service charge: 50
Deposit of 500.0 done. Balance: 2500.0
Withdrawal rejected: insufficient balance.
Name: Om Jha
Account number: 6006
Balance: 2500.0
Account type: Current
Minimum balance: 1000.0
Service charge: 50.0Sample 5
Enter account type (S for Savings, C for Current): S
Enter name: Test
Enter account number: 7007
Enter opening balance: -100
Enter deposit amount: 500
Enter withdrawal amount: 200
INVALID INPUTDry run
Take the third sample: type C, name Ravi Kumar, accNo 2002, bal 5000, dep 1000, wd 5500, minBal 1000, charge 50.
| Step | Statement | balance | Other values |
|---|---|---|---|
| 1 | ob = new Current(...) calls super(n, a, b) | 5000 | minBal = 1000, charge = 50 |
| 2 | ob.deposit(1000): balance = 5000 + 1000 | 6000 | |
| 3 | ob.withdraw(5500) runs Current.withdraw(), which calls super.withdraw(5500); 5500 > 6000 is false, balance = 6000 - 5500 | 500 | done = true |
| 4 | done && balance < minBal: 500 < 1000 is true, balance = 500 - 50 | 450 | |
| 5 | ob.update() runs Account.update(), which does nothing | 450 | |
| 6 | ob.display() runs Current.display() | 450 |
The final balance is 450.0, as in the third sample run.
Variations
- Overdraft "Allow a Current account to be overdrawn up to a given limit and charge a fee when it is used."
- Compound interest "Add interest for n years on a Savings account, adding the interest to the balance every year."
- Abstract class "Make
Accountan abstract class with an abstract methodwithdraw()and define it inSavingsandCurrent."