Discussion
Which line will cause a compilation error?
public class Sample88
{
private final java.util.Map<String, Integer> tally =
new java.util.HashMap<String, Integer>();
void record(String key)
{
Assert key != null;
tally.put(key, tally.size() + 1);
}
public static void main(String[] args)
{
Sample88 s = new Sample88();
s.record("first");
System.out.println(s.tally);
}
}
Answer: D
Java keywords are lowercase, so Assert with a capital A is read as a type name and the line does not compile. There is no such class in scope. The keyword is simply assert, and no import can make the capitalised form work.
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