Home Tutorial Java Scjp Part11 SCJP Module-11 Question-2

 
 

Share on Google+Share on Google+
SCJP Module-11 Question-2
Posted on: July 17, 2010 at 12:00 AM
Advertisement
The given code below will test your knowledge about the Serializable Interface and how to Serializing the object.

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.

Answer:

(A)

Advertisement

Related Tags for SCJP Module-11 Question-2:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 17, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com