Share on Google+Share on Google+

SCJP Module-11 Question-1

Advertisement
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)

Advertisements

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

Share this Tutorial 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.