Discussion
Which two statements are true about wrapper or String classes?
1.If x and y refer to instances of different wrapper classes, then the fragment x.equals(y) will cause a compiler failure.
2.If x and y refer to instances of different wrapper classes, then x == y can sometimes be true.
3.If x and y are String references and if x.equals(y) is true, then x == y is true.
4.If x, y, and z refer to instances of wrapper classes and x.equals(y) is true, and y.equals(z) is true, then z.equals(x) will always be true.
5.If x and y are String references and x == y is true, then y.equals(x) will be true.
Answer: D
Statement (4) describes an example of the equals() method behaving transitively. By the way, x, y,and z will all be the same type of wrapper. Statement (5) is true because x and y are referring to the same String object.
Statement (1) is incorrect-the fragment will compile. Statement (2) is incorrect because x == y means that the two reference variables are referring to the same object. Statement (3) will only be true if x and y refer to the same String. It is possible for x and y to refer to two different String objects with the same value.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development