🔍 Java Scope Visualization

ScopeRules Class - Identifier Visibility Analysis

Class Scope
Method Scope
Parameter Scope
Block Scope
⚠️ Hidden/Shadowed

📝 Original Java Code

public class ScopeRules
{
    // CLASS LEVEL SCOPE
    static final double rate = 10.50;
    static int z;
    static double t;
    static int w;
    
    // METHOD main()
    public static void main(String[] args)
    {
        int num;
        double x;
        double z;
        char ch;
    }
    
    // METHOD one()
    public static void one(int x, char y)
    {
        // Method body
    }
    
    // METHOD two()
    public static void two(int one, int z)
    {
        char ch;
        int a;
        
        // BLOCK THREE
        {
            int x = 12;
        }
    }
}

📊 Visual Scope Hierarchy

CLASS SCOPE
rate z t w
METHOD main()
args num x z (shadows class z) ch
✓ Can access: rate, t, w (class vars), args (param)
⚠️ Class variable 'z' is hidden by local variable
METHOD one()
x y
✓ Can access: rate, z, t, w (class vars), x, y (params)
METHOD two()
one (shadows method) z (shadows class z) ch a
BLOCK THREE
x
✓ Can access: all of method two's scope + block's x
✓ Can access: rate, w (class vars), one, z, ch, a
⚠️ Class variable 'z' is hidden by parameter
⚠️ Method name 'one' is hidden by parameter

📋 Detailed Scope Analysis

Identifier Line Declared Kind Scope (Visible In) Status
rate 2 Class Variable Entire class (all methods) ✓ Always visible
z (class) 3 Class Variable Entire class, but can be hidden
t 4 Class Variable Entire class ✓ Always visible
w 16 Class Variable Entire class ✓ Always visible
main() 5 Method Entire class ✓ Always accessible
args 5 Parameter main() method only ✓ main() only
num 7 Local Variable main() method only ✓ main() only
x (main) 8 Local Variable main() method only ✓ main() only
z (main) 8 Local Variable main() method only
ch (main) 9 Local Variable main() method only ✓ main() only
one() 12 Method Entire class ✓ Always accessible
x (one) 12 Parameter one() method only ✓ one() only
y 12 Parameter one() method only ✓ one() only
two() 17 Method Entire class ✓ Always accessible
one (two) 17 Parameter two() method only
z (two) 17 Parameter two() method only
ch (two) 18 Local Variable two() method only ✓ two() only
a 19 Local Variable two() method only ✓ two() only
x (block) 21 Block Variable Block three only (inside two()) ✓ Block three only

📌 Summary by Scope Type

🏛️ Class Scope

Visible everywhere in the class

📱 Method Scope

Visible only within specific methods

main():
one():
two():

📦 Block Scope

Visible only within specific blocks

Block three (inside two()):

✅ This block can also see all of two()'s scope

❌ Variables from block not visible outside

⚠️ Shadowing/Hiding Examples

1. Class variable 'z' is shadowed:
2. Method name 'one' is shadowed:
✅ Accessibility Rules: