title: What is variable shadowing used for in a Java class?
body: <p>I'm reading my Deitel, Java How to Program book and came across the term <em>shadowing</em>. If shadowing is allowed, what situation or what purpose is there for it in a Java class?</p>
  
  <p>Example:</p>
  
  <pre><code>public class Foo {
  
      int x = 5;
  
      public void useField() {
          System.out.println(this.x);
      }
      public void useLocal() {
          int x = 10;
          System.out.println(x);
      }
  }
  </code></pre>