SCJP Module-11 Question-3


 

SCJP Module-11 Question-3

The Sample code given below will test your understanding about the FileOutputStream and ObjectOutputStream in Java.

The Sample code given below will test your understanding about the FileOutputStream and ObjectOutputStream in Java.

Given a sample code:

import java.io.*;

class Upper {
}

class Test implements Serializable {

Upper a = new Upper();

public static void main(String[] args) {
Test b = new Test();
try {
FileOutputStream fs = new FileOutputStream("file.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(b);
os.close();
} catch (Exception e) {
e.printStackTrace();
}}}

What will be result of above program when compiled and run?

(A) Fail to compile
(B) class Upper is not Serializable so it raise java.io.NotSerializableException.
(C) Compile and run sucessfully.
(D) An instance of Test is serialized.

Answer:

(A)

Ads