Page: 2
11. java.io package and Serialization
Q: 05 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 Q: 06 Assuming that the serializeBanana2() and the deserializeBanana2() methods will correctly use Java serialization and given: 13. import java.io.*; 14. class Food {Food() { System.out.print("1"); } } 15. class Fruit extends Food implements Serializable { 16. Fruit() { System.out.print("2"); } } 17. public class Banana2 extends Fruit { int size = 42; 18. public static void main(String [] args) { 19. Banana2 b = new Banana2(); 20. b.serializeBanana2(b); // assume correct serialization 21. b = b.deserializeBanana2(b); // assume correct 22. System.out.println(" restored " + b.size + " "); } 23. // more Banana2 methods 24. } 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 Q: 7 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 Question: 8 Given: 10. class MakeFile { 11. public static void main(String[] args) { 12. try { 13. File directory = new File(”d”); 14. File file = new File(directory,”f”); 15. if(!file.exists()) { 16. file.createNewFile(); 17. } 18. } catch (IOException e) { 19. e.printStackTrace 20. } 21. } 22. } 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
Page: 2
1
2
3
4
|