Commit 4cbfb15
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- Section10Methods/LocalandGlobalVariables/src
1 file changed
+0
-7
lines changedLines changed: 0 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | 1 | | |
9 | 2 | | |
10 | 3 | | |
| |||
0 commit comments