What is better way to compare class of two objects
<p>I can compare two different objects to know whether they belong to same class or different using both <code>==</code> operator and <code>equals</code> method also. But which one is the better approach and how? Have a look on both approach that i followed. What is better way to compare class of two objects</p>

<pre><code> //r2 and r3 are two different objects    
//first approach   Using == operator
    boolean firstApproach = ((Object)(r2.getClass()) ==((Object)r3.getClass()));

//second approach   Using equals method to compare
            boolean secondApproach = ((Object)(r2.getClass())).equals(((Object)r3.getClass()));
            System.out.println("...firstApproach ..."+firstApproach +"...secondway.."+secondway );
</code></pre>
