Discussion
What will be the output of the program?
public class Case22
{
public static void main(String[] args) throws Exception
{
Integer x = 1000;
int y = 1000;
System.out.println(x == y);
}
}
Answer: B
Comparing a wrapper with a primitive unboxes the wrapper first, so this is an int comparison of 1000 with 1000 and the answer is true. The cache is irrelevant because no reference comparison happens. Only wrapper against wrapper compares identity.
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