Discussion
Which line contains the error?
public class Sample71
{
public static void main(String[] args)
{
int grade = 75;
switch (grade / 10)
{
case 7:
assert grade >= 70 && grade < 80;
case 6:
System.out.println("pass");
break;
default:
System.out.println("other");
}
}
}
Answer: C
The case 7 branch has no break, so control falls through into case 6 and prints pass by accident rather than by design. The assertion above it is true and passes. Fall-through is legal and occasionally intended, but here it makes the 70s share a branch with the 60s silently.
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