Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Assume that a, b and c refer to wrapper classes

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume that a, b, and c refer to instances of primitive wrapper classes. Which of the following statements are correct?

Please choose 2 answers.

a.equals(a) will always return true.
b.equals(c) may return false even if c.equals(b) returns true.
a.equals(b) returns same as a == b.
a.equals(b) throws an exception if they refer to instances of different classes
a.equals(b) returns false if they refer to instances of different classes.

Stuck on this, could someone tell me the answers and explain why.

Thanks.
 
lowercase baba
Posts: 12871
62
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you first explain what you think the answer is and why?
 
Sheriff
Posts: 7646
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider also technique for such type of questions by eliminating some answers as obviuosly not considerable.
 
Marshal
Posts: 69779
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please always tell us where such material comes from. You may find answering easier if you review the general contract for the equals() method . I presume that wrapper class means one of the following eight classes, all in the java.base/java.lang package: Boolean, Byte, Character, Double, Float, Integer, Long, Short. You may find looking at their equals() methods helpful, too.
    Bookmark Topic Watch Topic
  • New Topic