D. An instance of Forest and an instance of Tree are both serialized.
Answer: B
2. Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:
What is the result?
A. restore 400
B. restore 403
C. restore 453
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: C
3. Which three statements concerning the use of the java.io.Serializable interface are true? (Choose three.)
A. Objects from classes that use aggregation cannot be serialized.
B. An object serialized on one JVM can be successfully deserialized on a different JVM.
C. The values in fields with the volatile modifier will NOT survive serialization and deserialization.
D. The values in fields with the transient modifier will NOT survive serialization and deserialization.
E. It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serializable.
Answer: B, D, E
4. Assuming that the serializeBanana2() and the deserializeBanana2() methods will correctly use Java serialization and given:
What is the result?
A. Compilation fails.
B. 1 restored 42
C. 12 restored 42
D. 121 restored 42
E. 1212 restored 42
F. An exception is thrown at runtime.
Answer: D
5. When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two?
A. closing the stream
B. flushing the stream
C. writing to the stream
D. marking a location in the stream
E. writing a line separator to the stream
Answer: E
6. Given the program
The current directory does NOT contain a directory named "d." Which three are true? (Choose three.)
A. Line 16 is never executed.
B. An exception is thrown at runtime.
C. Line 13 creates a File object named "d."
D. Line 14 creates a File object named "f."
E. Line 13 creates a directory named "d" in the file system.
F. Line 16 creates a directory named "d" and a file 'f' within it in the file system.
G. Line 14 creates a file named 'f' inside of the directory named “d” in the file system.
Answer: BCD
7. Given the program
Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?
A. s.writeInt(x);
B. s.serialize(x);
C. s.writeObject(x);
D. s.defaultWriteObject();
Answer: D
8. Given:
//bw is a reference to a valid BufferedWriter And the snippet:
15. BufferedWriter b1 = new BufferedWriter(new File("f"));
16. BufferedWriter b2 = new BufferedWriter(new FileWriter("f1"));
17. BufferedWriter b3 = new BufferedWriter(new PrintWriter("f2"));
18. BufferedWriter b4 = new BufferedWriter(new BufferedWriter(bw));
What is the result?
A. Compilation succeeds.
B. Compilation fails due only to an error on line 15.
C. Compilation fails due only to an error on line 16.
D. Compilation fails due only to an error on line 17.
E. Compilation fails due only to an error on line 18.
F. Compilation fails due to errors on multiple lines.
Answer:
-> B is correct. BufferedWriters can be constructed only by wrapping a Writer. Lines 16, 17, and 18 are correct because BufferedWriter, FileWriter, and PrintWriter all extend Writer. (Note: BufferedWriter is a decorator class. Decorator classes are used extensively in the java.io package to allow you to extend the functionality of other classes.)
-> A, C, D, E, and F are incorrect based on the above.
9. Given the program
What is the result? (Choose all that apply.)
A. exc
B. done
C. Compilation fails.
D. Exactly one object is serialized.
E. Exactly two objects are serialized.
Answer:
-> A is correct. An instance of type Computer Has-a Keyboard. Because Keyboard doesn't implement Serializable, any attempt to serialize an instance of Computer will cause an exception to be thrown.
-> B, C, D, and E are incorrect based on the above. If Keyboard did implement Serializable then two objects would have been serialized.
10. Given the program
and that the invocation java IOTest file2.txt is issued from a directory that has two subdirectories, "dir1" and "dir1", and that "dir1" has a file "file1.txt" and "dir2" has a file "file2.txt", and the output is "false true", which set(s) of code fragments must be inserted? (Choose all that apply.)
A. String path = d;
System.out.print(file.exists() + " ");
B. String path = d;
System.out.print(file.isFile() + " ");
Answer:
-> A and B are correct. Because you are invoking the program from the directory whose direct subdirectories are to be searched, you don't start your path with a File.separator character. The exists() method tests for either files or directories; the isFile() method tests only for files. Since we're looking for a file, both methods work.
-> C and D are incorrect based on the above
11. Given the program
Which are true? (Choose all that apply.)
A. Compilation fails.
B. The output is 10 0 9
C. The output is 10 0 10
D. The output is 10 7 9
E. The output is 10 7 10
F. In order to alter the standard deserialization process you would override the readObject() method in SpecialSerial.
G. In order to alter the standard deserialization process you would override the defaultReadObject() method in SpecialSerial.
Answer:
C and F are correct. C is correct because static and transient variables are not serialized when an object is serialized. F is a valid statement.
A, B, D, and E are incorrect based on the above. G is incorrect because you don't
override the defaultReadObject() method, you call it from within the overridden
readObject() method, along with any custom read operations your class needs.
I have over 7+ years of experience as a technical lead and have worked at both small startups and large organizations. While I'm a proficient full-stack developer, my expertise is in building scalable backend micro-services (API, Services, Data processing, async processing, multi-threaded services and data analysing) and build the client side UI (single page angular/react applications, Multiplatform rendering using bootstrap or material).
No comments:
Post a Comment