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

Home > Java Programming > File > Questions and Answers

Q: What is the output for the below code ?
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();
}
}
}
A. Compilation Fail B. java.io.NotSerializableException: Because class A is not Serializable
C. No Exception at Runtime D.

None of the above

Answer and Explanation

Answer:No Exception at Runtime

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.