Discussion
The program is run with java Snippet28 - what will be the output?
import java.util.*;
public class Snippet28
{
public static void main(String[] args)
{
Map<String, Integer> ages = new HashMap<String, Integer>();
ages.put("amy", 30);
Integer gone = ages.remove("amy");
assert gone != null;
System.out.println(ages.isEmpty());
}
}
Answer: D
This is the corrected form of the previous mistake. The removal happens as an ordinary statement, so it runs whether or not assertions are enabled, and only the check of its returned value sits inside the assert. The map ends up empty either way, so the printed result no longer depends on the -ea flag.
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