Skip to content

Commit 4cbfb15

Browse files
committed
feat: Demonstrate combined use of instance and static (global) variables in BankAccount model [bank-static-instance]
🎯 Purpose: Show how instance and static variables can coexist to model both per-object and shared data using a banking context. 📌 Key Features: - 👤 **Instance Variables** (`accountHolder`, `balance`): Unique for each `BankAccount` object. - 🌐 **Static Variable** (`interestRate`): Shared across all bank accounts globally. - 🔁 When `interestRate` is updated (e.g., from 5.0% to 6.5%), **all accounts reflect the change** automatically. - 💰 Method `calculateInterest()` computes interest dynamically using the shared rate. 📦 Class Breakdown: - `BankAccount`: Contains logic for interest calculation and displaying account details. - `CombinedUseOfInstanceGlobalVariable`: Main runner that creates multiple accounts, displays data, and shows the effect of modifying the static variable. 📊 Use Case Summary: | Type | Example Use in Code | |------------------------|--------------------------------------------------| | Instance Variables | `accountHolder`, `balance` | | Global Static Variable | `interestRate` shared by all accounts | | Combined Usage | Changing global rate updates all account output | 🔑 Key: `bank-static-instance` ✅ Reinforces the power of `static` for shared constants/configs and instance fields for per-object state. Signed-off-by: Somesh diwan <[email protected]>
1 parent 10997ef commit 4cbfb15

File tree

1 file changed

+0
-7
lines changed

1 file changed

+0
-7
lines changed

Section10Methods/LocalandGlobalVariables/src/CombinedUseOfInstanceGlobalVariable.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/*
2-
Key Features:
3-
Each account has its own accountHolder and balance (Instance Variables).
4-
interestRate is shared across all accounts (Global Variable).
5-
Updating interestRate affects all accounts.
6-
*/
7-
81
class BankAccount {
92
private String accountHolder; // Instance variable (unique per object)
103
private double balance; // Instance variable

0 commit comments

Comments
 (0)