Commit 9d4185f
committed
feat: Illustrate global static variable usage with shared companyName across all employee instances [global-variable-sharing]
📌 Core Concept:
Demonstrates how a static (global) variable is shared across all instances of a class, and how modifying it reflects across all objects.
🏢 Program Overview:
- `Company` class:
- Instance Variables: `employeeName`, `salary` – unique for each object.
- Static Variable: `companyName` – shared across all instances.
- Constructor initializes individual employee details.
- `display()` method prints employee + company data.
🧪 Behavior:
- Initially, all objects reflect `companyName = "Tech Corp"`.
- After updating `Company.companyName = "Global Tech"`, the change reflects for all employee objects instantly.
📌 Key Features:
- Shared class-level state with `static` keyword.
- Demonstrates difference between object-specific vs shared attributes.
✅ Useful pattern for:
- Application-wide constants
- Branding/labels
- Environment configuration across objects
Signed-off-by: Somesh diwan <[email protected]>1 parent be981d9 commit 9d4185f
File tree
1 file changed
+9
-9
lines changed- Section10Methods/LocalandGlobalVariables/src
1 file changed
+9
-9
lines changedLines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 1 | | |
10 | 2 | | |
11 | 3 | | |
| |||
41 | 33 | | |
42 | 34 | | |
43 | 35 | | |
44 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
0 commit comments