Java Reference
In-Depth Information
5. Given the following code:
6. try {
7. File f = new File(“./test/”);
8. if(!f.exists()) {
9. f.mkdir();
10. }
11.
12. File g = new File(“./test/something.txt”);
13. g.createNewFile();
14. }catch(IOException e) {
15. e.printStackTrace();
16. }
and assuming that the current directory from which this program is executed does not
contain any subdirectories and that no exceptions are thrown, which of the following
statents are true? (Select two answers.)
A. A new subdirectory named test is created in the current directory.
B. A new file named something.txt is created in the current directory.
C. A new file named something.txt is created in the test subdirectory.
D. The mkdir and createNewFile methods are not defined for objects of type java
.io.File.
E. A new file named test is created in the current directory.
6. Which of the following statements are true? (Select three. )
A. All string literals are automatically instantiated into a String object.
B. The StringBuilder and StringBuffer classes define the exact same public methods.
C. In a multithreaded environment, use StringBuilder instead of StringBuffer.
D. A StringBuilder object is immutable.
E. A StringBuffer object can increase its length when appending characters.
7. What is the result of the following code?
4. String s = “Hello”;
5. String t = new String(s);
6.
7. if(“Hello”.equals(s)) {
8. System.out.print(“one”);
9. }
10.
11. if(t == s) {
12. System.out.print(“two”);
Search WWH ::




Custom Search