Skip to content

Commit 7a5d1e2

Browse files
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

1 file changed

+0
-1
lines changed

Section10Methods/LocalandGlobalVariables/src/staticvariable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
public class staticvariable {
22
static int a=10;
3-
43
void fun() {
54
int b=10;
65
System.out.println(a+" "+b);

0 commit comments

Comments
 (0)