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; } } }
| 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 | ⚠️ Hidden in main() and two() |
| 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 | ⚠️ Shadows class variable z |
| 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 | ⚠️ Shadows method name one() |
| z (two) | 17 | Parameter | two() method only | ⚠️ Shadows class variable z |
| 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 |
Visible everywhere in the class
Visible only within specific methods
Visible only within specific blocks
✅ This block can also see all of two()'s scope
❌ Variables from block not visible outside