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

 
 

Share on Google+Share on Google+
SCJP Module-11 Question-3
Posted on: July 17, 2010 at 12:00 AM
Advertisement
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)

Advertisement

Related Tags for SCJP Module-11 Question-3:


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