title: Can I override a private method in Java?
body: <p>I know I can use reflection to invoke a private method, and to get or set the value of a private variable, but I want to override a method.</p>
  
  <pre><code>public class SuperClass {
  
      public void printInt() {
          System.out.println("I am " + getClass() + ". The int is " + getInt());
      }
  
      private int getInt() {
          return 1;
      }
  }
  
  public class SubClass extends SuperClass {
  
      public static void main(String[] args) {
          (new SubClass()).printInt();
      }
  
      public int getInt() {
          return 2;
      }
  }
  </code></pre>
  
  <p>I want the <code>main</code> method in <code>SubClass</code>  to print out <code>2</code>, but it prints out <code>1</code>.
  I've heard this can be done through reflection, but I can't figure out how. 
  If not reflection, does anyone know of another way of doing it? 
  (Other than making <code>SuperClass.getInt()</code> protected, or copying and pasting the <code>printInt()</code> method into <code>SubClass</code>.)
  If actually overriding the private method is not possible, is there a way of placing some sort of trigger on it that will invoke a method in my sub-class either before or after the private method executes?</p>