decorative ruler line

Todays SCJP Mock Exam Question - Saturday 4-July-2009

lower decorative ruler line
Site Logo

TigerTamer for Java 5: The book. A 200 page intense tutorial on the JDK 1.5 exam. See http://www.examulator.com/tamer

These mock exam questions are generated each day from a database of 320 questions. They are very close to the style of the the real Sun Certified Java Programmers exam. Getting the same question each day?, try pressing your browser refresh key at the same time as the control key. The question topics are all from those in the published objectives for the JDK 1.5 exam. All questions were developed by Marcus Green over the last four years. For more information see here info.php

Question No=292

What will happen when you attempt to compile and run the following code?
import java.io.*;
public class ObSave{
    public static void main(String argv[]) throws IOException{
	ObSave o = new ObSave();
	o.go();
    }
    public void go() throws IOException{
	String[] obs = {"one","two","three"};
	FileOutputStream out = new FileOutputStream("mystrings.ob");
	ObjectOutputStream s = new ObjectOutputStream(out);
	s.writeObject(obs);
	s.flush();
    }

}
1 Compile time error writeObject can only take an object, not a String array
2 Compilation error, String array is missing the new operator
3 Compilation, but runtime error
4 Compilation and output of the serialized content of the obs String array to a new file called mystrings.ob