title: Variable shadowing in Java
body: <p>I am having some doubts about this Java code. The output it gives is &quot;furry bray&quot;. My questions:</p>
  <ol>
  <li>Why do i get this output?</li>
  <li>How can I access the String object reference &quot;name&quot; in ZooKeeper class?</li>
  <li>If it has something to do with variable shadowing, then which variable is being shadowed?</li>
  </ol>
  <h3>Code:</h3>
  <pre><code>class Mammal {
     String name = &quot;furry &quot;;
     String makeNoise() { return &quot;generic noise&quot;; }
   }
   class Zebra extends Mammal {
     String name = &quot;stripes &quot;;
     String makeNoise() { return &quot;bray&quot;; }
   }
   public class ZooKeeper {
     public static void main(String[] args) { new ZooKeeper().go(); }
     void go() {
       Mammal m = new Zebra();
       System.out.println(m.name + m.makeNoise());
       //Output comes as &quot;furry bray&quot;. Please explain this.
       //And how can we access the name variable, the one having &quot;stripes &quot; in it.
       //Does it have something to do with Variable Shadowing?
     }
   }
  </code></pre>