SCJP Module-11 Question-1


 

SCJP Module-11 Question-1

The sample code will examine your knowledge FileOutputStream, ObjectOutputStream and how these classes are used to printing out data from the file.

The sample code will examine your knowledge FileOutputStream, ObjectOutputStream and how these classes are used to printing out data from the file.

Given a sample code:

import java.io.*;

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

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

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

(A) An instance of Test is serialized.
(B) Compile time error. 
(C) Compile and run successfully but not serialized.
(D) An exception is thrown at runtime.

Answer:

(A)

Ads