class Account { protected String accountNumber; protected double balance; public Account(String accountNumber, double initialBalance) { this.accountNumber = accountNumber; this.balance = initialBalance; } public void deposit(double amount) { balance += amount; System.out.println(accountNumber + ": Deposited " + amount + ", new balance = " + balance); } public void withdraw(double amount) { if (balance >= amount) { balance -= amount; System.out.println(accountNumber + ": Withdrew " + amount + ", new balance = " + balance); } else { System.out.println(accountNumber + ": Insufficient balance to withdraw " + amount); } } public double getBalance() { return balance; } public String getAccountNumber() { return accountNumber; } } class SavingsAccount extends Account { private double interestRate; // e.g., 0.05 = 5% public SavingsAccount(String accountNumber, double initialBalance, double interestRate) { super(accountNumber, initialBalance); this.interestRate = interestRate; } public void applyInterest() { double interest = balance * interestRate; deposit(interest); System.out.println(accountNumber + ": Interest applied: " + interest); } public double getInterestRate() { return interestRate; } } class CheckingAccount extends Account { private double overdraftLimit; public CheckingAccount(String accountNumber, double initialBalance, double overdraftLimit) { super(accountNumber, initialBalance); this.overdraftLimit = overdraftLimit; } @Override public void withdraw(double amount) { if (balance + overdraftLimit >= amount) { balance -= amount; System.out.println(accountNumber + ": Withdrew " + amount + ", new balance = " + balance); } else { System.out.println(accountNumber + ": Exceeded overdraft limit! Cannot withdraw " + amount); } } public double getOverdraftLimit() { return overdraftLimit; } } public class Example02 { public static void main(String[] args) { SavingsAccount savings = new SavingsAccount("SAV-001", 1000, 0.05); CheckingAccount checking = new CheckingAccount("CHK-001", 500, 200); // Common behavior savings.deposit(200); checking.withdraw(600); // Specialized behavior savings.applyInterest(); checking.withdraw(200); // triggers overdraft System.out.println("Savings balance: " + savings.getBalance()); System.out.println("Checking balance: " + checking.getBalance()); } }