Page: 1
11. java.io package and Serialization
Q: 01 Click the Task button.
 Solution: reader = new BufferedReader(new FileReader("in"); writer = new PrintWriter (new BufferedWriter (new FileWriter("out"))); Q: 02 Given: 12. import java.io.*; 13. public class Forest implements Serializable { 14. private Tree tree = new Tree(); 15. public static void main(String [] args) { 16. Forest f = new Forest(); 17. try { 18. FileOutputStream fs = new FileOutputStream("Forest.ser"); 19. ObjectOutputStream os = new ObjectOutputStream(fs); 20. os.writeObject(f); os.close(); 21. } catch (Exception ex) { ex.printStackTrace(); } 22. } } 23. 24. class Tree { } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. An instance of Forest is serialized. D. An instance of Forest and an instance of Tree are both serialized. Answer: B Q: 03 Click the Task button. 
Solution: - (temp = buffReader.readLine())
- != null
- (IOException e){
Q: 04 Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given: 13. import java.io.*; 14. class Food implements Serializable {int good = 3;} 15. class Fruit extends Food {int juice = 5;} 16. public class Banana extends Fruit { 17. int yellow = 4; 18. public static void main(String [] args) { 19. Banana b = new Banana(); Banana b2 = new Banana(); 20. b.serializeBanana(b); // assume correct serialization 21. b2 = b.deserializeBanana(); // assume correct 22. System.out.println("restore "+b2.yellow+ b2.juice+b2.good); 24. } 25. // more Banana methods go here 50. } 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
Page: 1
1
2
3
4
|