Discussion :: Declarations and Access Control
-
which two statements, added independently at beginning of the program, allow the code to compile?/* Missing statements ? */ public class NewTreeSet extends java.util.TreeSet { public static void main(String [] args) { java.util.TreeSet t = new java.util.TreeSet(); t.clear(); } public void clear() { TreeMap m = new TreeMap(); m.clear(); } }
- No statement is required
- import java.util.*;
- import.java.util.Tree*;
- import java.util.TreeSet;
- import java.util.TreeMap;
Answer : Option B
Explanation :
(2) and (5). TreeMap is the only class that must be imported. TreeSet does not need an import statement because it is described with a fully qualified name.
(1) is incorrect because TreeMap must be imported. (3) is incorrect syntax for an import statement. (4) is incorrect because it will not import TreeMap, which is required.
Be The First To Comment