waltermilner

Scope

Jun 6th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.34 KB | None | 0 0
  1. public class Test { // illustrate scope
  2.  
  3.  
  4.   public static void main(String args[]) {
  5.     // x = 100; // not allowed - x not in scope
  6.     int x; // scope of x starts here
  7.     x = 5; // ok
  8.     System.out.println(x); // 5
  9.     if (true) {
  10.       int y = 7; // y scope starts here
  11.     } // ends here
  12. // y=9; not allowed - y out of scope
  13.   }
  14.  
  15. }
Advertisement
Add Comment
Please, Sign In to add comment