Explanation
This Java program simulates a basic banking system to demonstrate the principle of Inheritance. The core idea is to create a general template for a bank account and then specialize it for different types of banking products (Savings and Current accounts).
- The Base Class (
Account): This is the parent class. It contains common attributes that every bank account shares, regardless of its type, such as the customer's name, the account number, and the account type. It provides "getter" and "setter" methods to manage these basic details. - The Savings Class (
Savings): This class extendsAccount, meaning it inherits all the properties of the parent. It adds specific features like interest calculation. It uses the compound interest formula to update the balance and includes methods for cash deposits and withdrawals. - The Current Class (
Current): This also extendsAccount. Unlike the Savings account, it focuses on business-style transactions like cheque deposits. It also implements a "Minimum Balance" rule: if a withdrawal causes the balance to drop below a certain threshold, a service charge is automatically deducted. - The Execution (
AccountMain): Themainmethod acts as the driver. It creates objects for bothSavingsandCurrentaccounts, populates them with data, and performs a series of transactions (deposits, interest application, withdrawals) to show how the inherited and specialized methods work in tandem.