Discussion
The program is run with java -ea Example07 - what will be the output?
public class Example07
{
public static void main(String[] args)
{
int used = 250;
int budget = 100;
assert used <= budget;
System.out.println("within budget");
}
}
Answer: C
With -ea the expression is evaluated, and 250 is not within a budget of 100, so the assertion is false and an AssertionError is thrown at that statement. The error propagates out of main, so the following print never runs. Nothing catches it, so the JVM reports the error and exits with a non-zero status.
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