123456789101112131415



Question 1: import java.io.*;
public class Forest implements Serializable {
private Tree tree = new Tree();
public static void main(String [] args) {
Forest f = new Forest();
try {
FileOutputStream fs = new FileOutputStream("Forest.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(f); os.close();
} catch (Exception ex) { ex.printStackTrace(); }
} }

class Tree { }

What is the result?

1. Compilation fails.
2. An exception is thrown at runtime.
3. An instance of Forest is serialized.
4. An instance of Forest and an instance of Tree are both serialized.