• 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

Object Comparison

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if o1 and o2 denote object reference to different objects of the same class, which of the following are true.
a. o1.equals(o2)
b. o1 == o2
c. o1.hashCode()==o2.hashCode()
d. Nothing can be said about o1.equals(o2)
e. Nothing can be said about o1==o2
Can someone tell me which of the above are correct .
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since o1 and o2 denote object reference to different objects of the same class I think answer is a.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a. o1.equals(o2) FALSE May or may not be true, depending on how equals() works for the class.
b. o1 == o2 FALSE Since o1 and o2 refer to different instances
c. o1.hashCode()==o2.hashCode() FALSE Depends on whether (a) is true or not
d. Nothing can be said about o1.equals(o2) DEPENDS on what "nothing" means. Obviously, I have said something about it in the explanation above. This option is ambiguous and could be stated better
e. Nothing can be said about o1==o2. FALSE see (b) above
Junilu

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic