Discussion
Which line rests on a mistaken assumption?
public class Sample30
{
public static void main(String[] args)
{
long start = System.currentTimeMillis();
work();
assert System.currentTimeMillis() - start < 100 : "too slow";
System.out.println("done");
}
static void work() { }
}
Answer: B
Elapsed time depends on the machine, its load and garbage collection, none of which the code controls, so this assertion can fail on correct behaviour. Assertions state facts that must be true by construction; performance belongs in a benchmark, not in an assert.
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