title: Are static variables inherited
body: <p>I have read at 1000's of locations that Static variables are not inherited. But then how this code works fine?</p>
  
  <p><strong>Parent.java</strong></p>
  
  <pre><code>public class Parent {
          static String str = "Parent";
      }
  </code></pre>
  
  <p><strong>Child.java</strong></p>
  
  <pre><code>public class Child extends Parent {
          public static void main(String [] args)
          {
              System.out.println(Child.str);
          }
      }
  </code></pre>
  
  <p>This code prints "Parent".</p>
  
  <p>Also read at few locations concept of data hiding.</p>
  
  <p><strong>Parent.java</strong></p>
  
  <pre><code>public class Parent {
      static String str = "Parent";
  }
  </code></pre>
  
  <p><strong>Child.java</strong></p>
  
  <pre><code>public class Child extends Parent {
      static String str = "Child";
  
      public static void main(String [] args)
      {
          System.out.println(Child.str);
      }
  }
  </code></pre>
  
  <p>Now the output is "Child".</p>
  
  <p>So does this mean that <strong>static variables are inherited but they follow the concept of data-hiding</strong>?</p>