Skip to content

Commit 7f2f399

Browse files
committed
feat: Distinguish between Local, Instance, and Static Variables with Examples and Comparison Table [var-scope-vip]
📌 Key Focus: Provides a comprehensive explanation of local, global (instance), and static variables in Java with real-world examples, scope clarification, and a full comparison table. 🧠 Core Concepts: - **Local Variable**: Declared within a method or block, short-lived, and not accessible outside. - **Instance Variable (Global)**: Declared inside the class but outside methods, persists as long as the object exists. - **Static Variable**: Declared with `static`, belongs to the class and shared among all objects, exists for the program lifetime. 📊 Includes: - Scope, lifetime, and access control for each variable type - Behavior of default values and initialization - Real Java code demonstrating each type in action - Output simulation and side-by-side table for easy comparison 💡 Educational Utility: Perfect for learners or interview prep – emphasizes **when** and **why** to use each variable type in class design or memory management. 🗂️ Commit Key: [var-scope-vip] Signed-off-by: Somesh diwan <[email protected]>
1 parent ead6ae8 commit 7f2f399

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Section10Methods/LocalandGlobalVariables/src/Local Variable vs Global (Instance) Variable.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Local Variable vs Global (Instance) Variable
22

3-
In Java, the distinction between local and global (or instance)** variables is essential to understanding
3+
In Java, the distinction between local and global (or instance) variables is essential to understanding
44
how variables are used within a class.
55

66
Local Variables:
@@ -126,4 +126,4 @@ Key Takeaways:
126126

127127
1. Local variables are temporary and limited to the method/block where they are declared.
128128
2. Global (instance) variables** are available throughout the class and persist with the object.
129-
3. Static variables are shared across all instances of a class and remain for the lifetime of the program.
129+
3. Static variables are shared across all instances of a class and remain for the lifetime of the program.

0 commit comments

Comments
 (0)