Discussion
Which line contains the error?
public class Sample94
{
private static final int RETRIES = 3;
static int attempt(java.util.Random rng)
{
assert true;
assert RETRIES == 3;
return rng.nextInt(RETRIES);
}
public static void main(String[] args)
{
System.out.println(attempt(new java.util.Random(7)));
}
}
Answer: B
Both conditions are constants the compiler can evaluate, so neither can ever report anything. They compile and pass, costing a little time under -ea and documenting nothing. An assertion earns its place only when it states something that could conceivably be 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