Discussion
The program is run with java -ea Item48 - what will be the output?
public class Item48
{
public static void main(String[] args)
{
Long x = 200L;
Long y = 200L;
assert x == y : "not cached";
System.out.println(x.equals(y));
}
}
Answer: D
200 is outside the guaranteed cache range of -128 to 127, which applies to Long just as it does to Integer, so each boxing conversion may produce a new object. The identity test is false and the assertion throws. The equals comparison in the unreached print would have been true.
No comment is present. Be the first to comment.
Loading…
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