title: How to display the SimpleClassName at each level of the inheritance hierarchy using a method that is inherited?
body: <p>I want to create a method <code>printKlass()</code> in my top-level class which is inherited and prints a top-level variable <code>KLASS</code> containing the value of <code>getClass().getSimpleName()</code>.</p>
  
  <p>So, in the case of class A, the <code>printKlass</code> method should write <code>A</code>.</p>
  
  <p>And class B should print <code>B</code>.</p>
  
  <p>But the compiler won't let me access the <code>getClass</code> method in the part class - it says <code>this</code> is not available in a <code>static</code> context.</p>
  
  <p>How do I get around this?</p>
  
  <pre><code>public class A 
  {
      protected static final String KLASS = this.getClass().getSimpleName(); // "Cannot use 'this' in a static context
  
      protected
      public void printKlass()
      {
          System.out.println(KLASS);
      }
  }
  
  public class B extends A
  {
  
      //...
  
      printKlass(); // Should say "B", not "A"
  
      //...
  
  }
  </code></pre>