Discussion
Which line contains the error?
public class Sample65
{
public static void main(String[] args)
{
assert check(2) : "even";
assert !check(2) : "odd";
System.out.println("consistent");
}
static boolean check(int n) { return n % 2 == 0; }
}
Answer: A
The two assertions contradict each other, so one must always fail whatever check() returns. The first passes for 2 and the second then throws. A pair like this usually survives an edit where a condition was negated in one place and not the other; the code can never satisfy both.
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