Discussion
Which line is an inappropriate use of an assertion?
public class Sample13
{
public static void main(String[] args)
{
assert args.length == 2 : "usage: Sample13 <in> <out>";
String in = args[0];
String out = args[1];
System.out.println(in + " -> " + out);
}
}
Answer: A
Command-line arguments come from outside the program, so validating them is part of its contract with the user, not an internal invariant. Without -ea the check vanishes and the next line throws ArrayIndexOutOfBoundsException instead of reporting the usage. Input validation needs an explicit test.
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