title: Private methods in Inheritance
body: <p>Here's an interesting code snippet:</p>
  
  <pre><code>public class Superclass {
  
      public static void main (String[] args){
          Superclass obj = new Subclass();
          obj.doSomething(); #prints "from Superclass"
      }
  
      private void doSomething(){System.out.println("from Superclass");}
  }
  
  class Subclass extends Superclass {
  
      private void doSomething(){System.out.println("from Subclass");}
  
  }
  </code></pre>
  
  <p>I know that subclasses do not inherit the private members of its parent, but here obj manages to call a method to which it should have no access. At compile time obj is of type Superclass, at runtime of type Subclass. </p>
  
  <p>This probably has something to do with the fact that the call to doSomething() is taking place inside the driver class, which happens to be its own class (and why it's possible to invoke doSomething() in the first place). </p>
  
  <p>So the question boils down to, how does obj have access to a private member of its parent?</p>