Discussion
The program is run with java -ea Case58 - what will be the output?
public class Case58
{
static boolean check(int n)
{
return n > 0;
}
public static void main(String[] args)
{
assert check(1) : "one";
assert check(-1) : "minus one";
System.out.println("end");
}
}
Answer: B
Assertions are evaluated in order. The first passes because check(1) returns true, so execution moves on. The second fails and throws with its own detail message, minus one, and the print is never reached. Only the first failing assertion is reported.
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