Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/what-cannot-be-serialized-in-java
Question 157 / 297:  What is the result of compiling and running the following code?
import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.Serializable;

public class Tester implements Serializable{

transient int x = 5;

public static void main(String[] args) {

Tester tester1 = new Tester();

try {

ObjectOutputStream os = new ObjectOutputStream(

new FileOutputStream("data.txt"));

os.writeObject(tester1);

os.close();

System.out.print(++tester1.x + " ");

ObjectInputStream is = new ObjectInputStream(new FileInputStream(

"data.txt"));

Tester tester2 = (Tester) is.readObject();

is.close();

System.out.println(tester2.x);

} catch (Exception x) {

System.out.println("Exception thrown");

}

}

}

A  5 5
B  6 5
C  6 0
D  An exception is thrown
<< First < Previous Next > Last >>
Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>