... useField(); // useField uses class Scope's field x
17         useLocalVariable(); // useLocalVariable reinitializes local x
18         useField(); // class Scope's field x retains its value
19
20         System.out.printf("%nlocal x in main is %d%n", x);
21      }
22
23      // create and initialize local variable x during each call
24      public static void useLocalVariable() {
25         int x = 25; // initialized each time useLocalVariable is called
26
27         System.out.printf(
28            "%nlocal x on entering method useLocalVariable is %d%n", x);
29         ++x; // modifies this method's local variable x
30         System.out.printf(
31            "local x before exiting method useLocalVariable is %d%n", x);
32      }
33
34      // modify class Scope's field x during each call
35      public static void useField() {
36 System.out.printf( ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.