Question: This program is run when there is no extant file named "Test Object.to". The output of this program is "IO caught". Why?

```
import java.io.*;

public class Test 
{
    public static void main (String [] args)
    {
        TestObject testObject = new TestObject("Test Object");

        try
        {
            saveTestObject(testObject);
        }
        catch (FileNotFoundException fnf)
        {
            System.out.println("FNF caught");
        }
        catch (IOException io)
        {
            System.out.println("IO caught");
        }
    }

    static void saveTestObject(TestObject to)  throws FileNotFoundException, IOException
    {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(to.name + ".to"));
        oos.writeObject(to);
        oos.close();
    }
}

class TestObject
{
    String name;

    TestObject(String s)
    {
        name = s;
    }
}

```

Answer: 
First of all, this does not throw a `FileNotFoundException`, since [as per the docs](https://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html#FileOutputStream(java.io.File)), `FileOutputStream`'s constructor will create the file if it doesn't exist instead of throwing an error. If you print the error, you see:

```
java.io.NotSerializableException: TestObject

```

Again, [as per the docs](https://docs.oracle.com/javase/7/docs/api/java/io/ObjectOutputStream.html#writeObject(java.lang.Object)), `writeObject` requires that its argument be [`Serializable`](https://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html). Since `Serializable` is just a marker interface, you can just implement it:

```java
class TestObject implements Serializable

```

and now your code doesn't throw any errors.
Ok I see now that TestObject obviously needs to implement Serializable