Welcome Guest | Sign in | Register
File - Discussion Page For Q.2728 | 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 class B implements Serializable {
private static 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();
}
}
}
What is the output for the above code ?
A. Compilation Fail B. java.io.NotSerializableException: Because class A is not Serializable.
C. No Exception D. None of the above

Answer and Explanation

Answer:No Exception

Explanation:
No java.io.NotSerializableException, Because class A variable is static. static
variables are not Serializable.

Comment on this Question

Name:

Loading...




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