Discussion
The program is run with java -ea Fragment90 - what will be the output?
import java.util.*;
public class Fragment90
{
public static void main(String[] args)
{
assert Objects.equals(null, null);
System.out.println(Objects.equals("a", null));
}
}
Answer: B
Objects.equals is null-safe: two nulls are equal, so the assertion passes, and comparing a non-null with null returns false rather than throwing. That is the whole reason the helper exists, since "a".equals(null) is safe but s.equals("a") with a null s is not.
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