Commit 7a5d1e2
committed
feat: Demonstrate behavior of static vs non-static variables in method context [StaticVsNonStaticVariable.png]
📌 Focus:
Illustrates how static (`a`) and non-static (`b`) variables behave across multiple method calls in Java using a simple class.
🧠 Logic:
- `static int a = 10`: Shared across all instances, retains its value between method calls.
- `int b = 10`: Local to `fun()` method, re-initialized every time the method is called.
- Method `fun()` increments both variables and prints them to show scope and memory persistence differences.
💡 Key Insight:
- `a` persists and accumulates due to static storage.
- `b` resets with each method call due to local scope.
Signed-off-by: Somesh diwan <[email protected]>1 parent 4f8f7d1 commit 7a5d1e2
File tree
1 file changed
+0
-1
lines changed- Section10Methods/LocalandGlobalVariables/src
1 file changed
+0
-1
lines changedLines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
0 commit comments