-1

I want to compare the super classes of two different objects.If it is same then it should ask for another opponnet. Unless it selects the type that is diffenret. I have the following code for it. But it always returns true.

boolean equal(Characters C)
{
    return (C.getClass().getSuperclass()== Char.getClass().getSuperclass());
}
     
      
ernest_k
  • 44,416
  • 5
  • 53
  • 99
Muskh
  • 1
  • We don't really have enough information to answer this for you. Are you trying to compare _which class_ is the superclass? The _values in_ the superclass? – Louis Wasserman Feb 16 '21 at 20:23
  • Why do you want to compare their super class? The easy way would be to have an id in each superclass. – NomadMaker Feb 17 '21 at 10:50

1 Answers1

0

we can compare the objects of different classes by calling O1.getClass()==O2.getClass() function of object if the object has same class it return true else false. In case of inheritance if we want to know that the two objects are belonging to same superclass or different then we calling O1.getClass().getSuperClass()==O2.getClass().getSuperClass() to campare.

Muskh
  • 1