Given a sample code:
import java.io.*;
class Upper {
public Upper() {
System.out.print(" Upper");
}
}
class Middle extends Upper implements Serializable {
public Middle() {
System.out.print(" Middle");
}
}
public class Test {
public static void main(String... args) throws Exception {
Middle b = new Middle();
ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream(
"serialize.ser"));
save.writeObject(b);
save.flush();
ObjectInputStream restore = new ObjectInputStream(new FileInputStream(
"serialize.txt"));
Middle z = (Middle) restore.readObject();
}
}
What will be result of above program when compiled and run?
(A) An instance of Middle is serialized.
(B) Compile time error.
(C) Compile and run successfully but not serialized.
(D) An exception is
thrown at runtime.
(A)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.