Discussion
The program is run with java -ea:com.acme... com.acme.util.Program32 - what will be the output?
package com.acme.util;
public class Program32
{
public static void main(String[] args)
{
String name = null;
assert name != null : "name missing";
System.out.println(name.length());
}
}
Answer: D
The three dots cover the named package and everything beneath it, and com.acme.util sits beneath com.acme, so assertions are enabled here. The assertion fails on the null name and throws before the dereference, turning what would have been a NullPointerException into a clear message. Compare the sibling-package case, where the switch named a package that is not an ancestor.
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