Given the following from the java.io.File API: Field Summary: static String separator Method Summary: static File[] listRoots()
And given:.
2. // insert code here 3. // insert code here 4. public class Main { 5. public static void main(String[] args) { 6. try { //from ww w . j a va 2s .co m 7. String s = "subdir" + separator + "myFile.txt"; 8. java.io.File f = new java.io.File(s); 9. java.io.FileReader fr = new java.io.FileReader(f); 10. java.io.File[] r = listRoots(); 11. fr.close(); 12. } 13. catch(Exception e) { } 14. } }
And the following four fragments:
I. import java.io.*; II. import static java.io.File.*; III. import static java.io.File.separator; IV. import static java.io.File.listRoots;
Which set(s) of fragments, inserted independently on lines 2 and/or 3, will compile? (Choose all that apply.)
B, E, and F are correct.
The code provides some fully qualified names from the java.
io package, but the names for the "separator" field and the listRoots()
method are not fully qualified.
Fragment II alone is the correct "static import" syntax, and therefore B and E are correct.
Fragment III provides the name for separator, and fragment IV provides the name for listRoots()
, so taken together III and IV will compile.