title: Java: get name of subclass from instance of superclass
body: <p>I have a class <code>public class N</code> and an object <code>A a = new B();</code></p>
  
  <p>The class B looks like this:</p>
  
  <pre><code>public class B extends A { ... }
  </code></pre>
  
  <p>I want to get a subclass name of the object <em>a</em> inside <em>N</em> as a String (also: <em>"B"</em>). How can i do this?</p>
  
  <p><strong>EDIT:</strong> In my case I use Visitor-Pattern. I have public void visit(A a), when a is previously defined as A a = new B(). Then I need to call public void visit(B b). How can I define, that I need to call exactly visit(B b)?</p>