Discussion
Which line will cause a compilation error?
public class Sample89
{
private final java.util.List<String> queue =
new java.util.LinkedList<String>();
void drain()
{
while (!queue.isEmpty())
{
assert;
queue.remove(0);
}
}
public static void main(String[] args)
{
new Sample89().drain();
}
}
Answer: A
Correct answer: assert;
The assert statement requires a boolean expression - either assert expr; or assert expr : detail; - so a bare assert; is a syntax error. The rest of the method is sound: queue.isEmpty() and queue.remove(0) are both valid on a List, and removing index 0 repeatedly is a legitimate way to drain one.
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