title: See if two object have the same type
body: <p>Let's say that I have a class A, and that B,C,D are derived from A.<br>
  If I want to know what's the type of an object referenced, I can declare:  </p>
  
  <pre><code>// pseudo-code
  if(obj instanceof B)
      &lt; is B&gt;
  else if(obj instanceof C)
      &lt; is C&gt;
  else
      &lt;is D&gt;
  </code></pre>
  
  <p>This because I am sure that the classes derived from A are only B,C and D.<br>
  But what if I want just to check that two references point to the same kind of object?<br>
  So something like:</p>
  
  <pre><code>if(obj1 instanceof obj2)
     &lt;do something&gt;
  </code></pre>
  
  <p>But of course the syntax is wrong.How to check this without one thousand if-else?</p>