aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question regarding using equals() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question regarding using equals()" Watch "question regarding using equals()" New topic
Author

question regarding using equals()

kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
Hi:
For exam Objective 5.2
it says :
the compiler will not allow == if the classes are not in the same hierarchy..

now my question is what does it mean by "classes are not in the same hierarchy"...does it mean classes not in the package or something else??
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

No, it's about inheritance. Parent class and subclass.


You can compare A and B, but you cannot compare String and Integer.


[My Blog]
All roads lead to JavaRanch
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Originally posted by Satou kurinosuke:
No, it's about inheritance. Parent class and subclass.


You can compare A and B, but you cannot compare String and Integer.


One more thing, this will work...



EDIT: As per your subject line: question regarding using equals(). It looks like you are asking whether equals() will work or not when classes are not in the same hierarchy? Call to inherited equals() will work even if there is not inheritance relationship between the classes as discussed below.

e.g.,



Naseem
[ September 07, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question regarding using equals()