Discussion
What will be the output of the program?
public class Trial21
{
Trial21()
{
Integer a = 127, b = 127;
Integer c = 128, d = 128;
System.out.println((a == b) + " " + (c == d));
}
public static void main(String[] args)
{
new Trial21();
}
}
Answer: A
Autoboxing an int between -128 and 127 must return a cached Integer, so a and b reference the same object and the first test is true. 128 is outside that guaranteed range, so each boxing may create a new object and the second is false. equals would be true in both cases.
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