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

Home > Java Programming > File > Questions and Answers

Q:
public class A implements Serializable {
transient int a = 7;
static int b = 9;
}
public class B implements Serializable {
public static void main(String... args){
A a = new A();
try {
ObjectOutputStream os = new ObjectOutputStream(
new FileOutputStream("test.ser"));
os.writeObject(a);
os. close();
System.out.print( + + a.b + " ");
ObjectInputStream is = new ObjectInputStream(new FileInputStream("test.ser"));
A s2 = (A)is.readObject();
is.close();
System.out.println(s2.a + " " + s2.b);
} catch (Exception x){
x.printStackTrace();
}
}
}
What is the output?
A. 9 0 9 B. 9 7 9
C. Runtime Exception D. Compile with error

Answer and Explanation

Answer:9 0 9

Explanation:
static and transient variables are not serialized when an object is serialized.

Comment on this Question

Name:

Loading...




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