SCJP Module-11 Question-10

The Sample class given below will test your understanding about the Stream classes in Java.

 
 

Share on Google+Share on Google+

SCJP Module-11 Question-10

Ads

The Sample class given below will test your understanding about the Stream classes in Java.

Consider a sample code:

1    public class Test implements Serializable {
2    private static final long serialVersionUID = 1L;

3    public static void main(String[] args) {
4    Test ts = new Test();
5    int value = 11;
6    try {
7    FileOutputStream fos = new FileOutputStream("savedata.ser");
8    ObjectOutputStream os = new ObjectOutputStream(fos);
9    os.writeObject(ts);
10    os.close();
11    // Place code here
12    ObjectInputStream is = new ObjectInputStream(fs);
13    Test ts2 = (Test) is.readObject();
14    System.out.print(ts2.value);
15    is.close();
16    } catch (Exception x) {
        }}}

What will be placed at line no-15 for desirialization ?

(A) FileInputStream fs = new FileInputStream(new DataOutputStream("savedata.ser"));
(B) FileInputStream fs = new FileInputStream("savedata.ser");
(C) DataOutputStream("new FileInputStream("savedata.ser") ");
(D) DataOutputStream("savedata.ser");

Answer:

(B)

Advertisements

Posted on: July 20, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles