Discussion
The program is run with java Sample01 - what will be the output?
public class Sample01
{
public static void main(String[] args)
{
int x = 5;
assert x > 10;
System.out.println("done");
}
}
Answer: A
Assertions are disabled by default, and a disabled assertion is semantically equivalent to an empty statement. The expression x > 10 is never evaluated, so no AssertionError can be thrown and the program falls through to the print. Only java -ea Sample01 would make this fail.
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