Discussion
Which line will cause a compilation error?
public class Sample77
{
private int low, mid, high;
void sort3(int x, int y, int z)
{
low = Math.min(x, Math.min(y, z));
high = Math.max(x, Math.max(y, z));
mid = x + y + z - low - high;
assert low < mid < high;
}
public static void main(String[] args)
{
new Sample77().sort3(9, 2, 5);
}
}
Answer: A
Java has no chained comparison. a < b produces a boolean, and comparing a boolean with the int c is a type error, so the line does not compile. The intended test is written with an explicit conjunction: assert a < b && b < c;.
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