Discussion
The program is run with java Listing29 - what will be the output?
public class Listing29
{
static StringBuilder log = new StringBuilder();
static boolean note(String s) { log.append(s); return false; }
public static void main(String[] args)
{
assert note("x") : note("y");
System.out.println(log);
}
}
Answer: A
Neither expression is evaluated when assertions are disabled, so nothing is appended and log is still empty. println of an empty StringBuilder prints an empty line. Under -ea both calls would run, in order, and the AssertionError message would be built from the second.
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