Welcome Guest | Sign in | Register
File - Discussion Page For Q.2696 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > File > Questions and Answers

Q: public class A {
public A() {
System.out.println("A");
}
}
public class Test {
public static void main(String... args) throws Exception {
A a = new A();
ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream("datafile"));
save.writeObject(a);
save.flush();
ObjectInputStream restore = new ObjectInputStream(new FileInputStream("datafile"));
A z = (A) restore.readObject();
}
}

What is the output?
A. A A B. A
C.  java.io.NotSerializableException D. None of the above

Answer and Explanation

Answer: java.io.NotSerializableException

Explanation:
Class A does not implements Serializable interface. So throws
NotSerializableException on trying to Serialize a non Serializable object.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.