Discussion
What will be the output of the program?
public class Listing73
{
public static void main(String[] args)
{
Long a = 127L;
Long b = 127L;
System.out.println((a == b) + " " + a.equals(127L) + " " + a.equals(127));
}
}
Answer: A
Long caches the same -128 to 127 range as Integer, so the identity test is true. equals against a long literal boxes it to Long and matches. equals against the int literal 127 boxes it to Integer, and a Long is never equal to an Integer whatever the value, so that one is false.
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