Multiple choice technology programming languages

What is the output for the below code ? public class A {} public class B implements Serializable { A a = new A(); public static void main(String... args){ B b = new B(); try{ FileOutputStream fs = new FileOutputStream("b.ser"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(b); os.close(); }catch(Exception e){ e.printStackTrace(); } } }

  1. Compilation Fail

  2. java.io.NotSerializableException: Because class A is not Serializable

  3. Run properly

  4. Compilation Fail : Because class A is not Serializable.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Class B implements Serializable, but it contains an instance variable of class A which is not Serializable. Since A does not implement Serializable and is not marked transient, serialization of B at runtime fails with java.io.NotSerializableException. It compiles fine.