• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question regarding using equals()

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's about inheritance. Parent class and subclass.


You can compare A and B, but you cannot compare String and Integer.
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic