Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
|
| Review Questions |
| 11.22 | How many methods are defined in the Serializable interface?
Select the one correct answer.
|
| 11.23 | Which of the following best describes the data written by an ObjectOutputStream?
Select the one correct answer.
|
| 11.24 | Given the following code:
Code View:
Scroll
/
Show All public class Person {
protected String name;
Person() { }
Person(String name) { this.name = name; }
}
________________________________________________________________________
import java.io.Serializable;
public class Student extends Person implements Serializable {
private long studNum;
Student(String name, long studNum) {
super(name);
this.studNum = studNum;
}
public String toString() { return "(" + name + ", " + studNum + ")"; }
}
________________________________________________________________________
import java.io.*;
public class RQ800_10 {
public static void main(String args[])
throws IOException, ClassNotFoundException {
FileOutputStream outputFile = new FileOutputStream("storage.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(outputFile);
Student stud1 = new Student("Aesop", 100);
System.out.print(stud1);
outputStream.writeObject(stud1);
outputStream.flush();
outputStream.close();
FileInputStream inputFile = new FileInputStream("storage.dat");
ObjectInputStream inputStream = new ObjectInputStream(inputFile);
Student stud2 = (Student) inputStream.readObject();
System.out.println(stud2);
inputStream.close();
}
}
Which statement about the program is true? Select the one correct answer.
|
| 11.25 | Given the following code:
Code View:
Scroll
/
Show All public class Person {
protected String name;
Person() { this.name = "NoName"; }
Person(String name) { this.name = name; }
}
_______________________________________________________________________
import java.io.Serializable;
public class Student extends Person implements Serializable {
private long studNum;
Student(String name, long studNum) {
super(name);
this.studNum = studNum;
}
public String toString() { return "(" + name + ", " + studNum + ")"; }
}
________________________________________________________________________
import java.io.*;
public class RQ800_20 {
public static void main(String args[])
throws IOException, ClassNotFoundException {
FileOutputStream outputFile = new FileOutputStream("storage.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(outputFile);
Student stud1 = new Student("Aesop", 100);
System.out.print(stud1);
outputStream.writeObject(stud1);
outputStream.flush();
outputStream.close();
FileInputStream inputFile = new FileInputStream("storage.dat");
ObjectInputStream inputStream = new ObjectInputStream(inputFile);
Student stud2 = (Student) inputStream.readObject();
System.out.println(stud2);
inputStream.close();
}
}
Which statement about the program is true? Select the one correct answer.
|
| 11.26 | Given the following code:
Code View:
Scroll
/
Show All import java.io.Serializable;
public class Person implements Serializable {
protected String name;
Person() { this.name = "NoName"; }
Person(String name) { this.name = name; }
}
________________________________________________________________________
public class Student extends Person {
private long studNum;
Student(String name, long studNum) {
super(name);
this.studNum = studNum;
}
public String toString() { return "(" + name + ", " + studNum + ")"; }
}
________________________________________________________________________
import java.io.*;
public class RQ800_30 {
public static void main(String args[])
throws IOException, ClassNotFoundException {
FileOutputStream outputFile = new FileOutputStream("storage.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(outputFile);
Student stud1 = new Student("Aesop", 100);
System.out.print(stud1);
outputStream.writeObject(stud1);
outputStream.flush();
outputStream.close();
FileInputStream inputFile = new FileInputStream("storage.dat");
ObjectInputStream inputStream = new ObjectInputStream(inputFile);
Student stud2 = (Student) inputStream.readObject();
System.out.println(stud2);
inputStream.close();
}
}
Which statement about the program is true? Select the one correct answer.
|
| 11.27 | Given the following code:
Code View:
Scroll
/
Show All import java.io.Serializable;
public class Person implements Serializable {
protected transient String name;
Person(String name) { this.name = name; }
}
________________________________________________________________________
public class Student extends Person {
private long studNum;
Student(String name, long studNum) {
super(name);
this.studNum = studNum;
}
public String toString() { return "(" + name + ", " + studNum + ")"; }
}
________________________________________________________________________
import java.io.*;
public class RQ800_40 {
public static void main(String args[])
throws IOException, ClassNotFoundException {
FileOutputStream outputFile = new FileOutputStream("storage.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(outputFile);
Student stud1 = new Student("Aesop", 100);
System.out.print(stud1);
outputStream.writeObject(stud1);
outputStream.flush();
outputStream.close();
FileInputStream inputFile = new FileInputStream("storage.dat");
ObjectInputStream inputStream = new ObjectInputStream(inputFile);
Student stud2 = (Student) inputStream.readObject();
System.out.println(stud2);
inputStream.close();
}
}
Which statement about the program is true? Select the one correct answer.
|
| 11.28 | Given the following code:
Code View:
Scroll
/
Show All import java.io.Serializable;
public class Person implements Serializable {
protected transient String name;
Person() { this.name = "NoName"; }
Person(String name) { this.name = name; }
}
________________________________________________________________________
import java.io.*;
public class Student extends Person {
private long studNum;
Student(String name, long studNum) {
super(name);
this.studNum = studNum;
}
public String toString() { return "(" + name + ", " + studNum + ")"; }
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
oos.writeObject("NewName");
}
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
ois.defaultReadObject();
name = (String) ois.readObject();
}
}
________________________________________________________________________
import java.io.*;
public class RQ800_50 {
public static void main(String args[])
throws IOException, ClassNotFoundException {
FileOutputStream outputFile = new FileOutputStream("storage.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(outputFile);
Student stud1 = new Student("Aesop", 100);
System.out.print(stud1);
outputStream.writeObject(stud1);
outputStream.flush();
outputStream.close();
FileInputStream inputFile = new FileInputStream("storage.dat");
ObjectInputStream inputStream = new ObjectInputStream(inputFile);
Student stud2 = (Student) inputStream.readObject();
System.out.println(stud2);
inputStream.close();
}
}
Which statement about the program is true? Select the one correct answer.
|
| 11.29 | Given the following code:
Code View:
Scroll
/
Show All public class Person {
protected transient String name;
Person() { this.name = "NoName"; }
Person(String name) { this.name = name; }
}
________________________________________________________________________
public class Student extends Person {
protected long studNum;
Student() { }
Student(String name, long studNum) {
super(name);
this.studNum = studNum;
}
}
________________________________________________________________________
import java.io.*;
public class GraduateStudent extends Student implements Serializable {
private int year;
GraduateStudent(String name, long studNum, int year) {
super(name, studNum);
this.year = year;
}
public String toString() {
return "(" + name + ", " + studNum + ", " + year + ")";
}
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
ois.defaultReadObject();
name = "NewName";
studNum = 200;
year =2;
}
}
________________________________________________________________________
import java.io.*;
public class RQ800_70 {
public static void main(String args[])
throws IOException, ClassNotFoundException {
FileOutputStream outputFile = new FileOutputStream("storage.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(outputFile);
GraduateStudent stud1 = new GraduateStudent("Aesop", 100, 1);
System.out.print(stud1);
outputStream.writeObject(stud1);
outputStream.flush();
outputStream.close();
FileInputStream inputFile = new FileInputStream("storage.dat");
ObjectInputStream inputStream = new ObjectInputStream(inputFile);
GraduateStudent stud2 = (GraduateStudent) inputStream.readObject();
System.out.println(stud2);
inputStream.close();
}
}
Which statement about the program is true? Select the one correct answer.
|
| 11.30 | Given the following code:
Code View:
Scroll
/
Show All import java.io.Serializable;
public class Person implements Serializable {
protected transient String name;
Person(String name) { this.name = name; }
}
_______________________________________________________________
public class Student extends Person {
private static int numOfStudents;
private long studNum;
Student(String name, long studNum) {
super(name);
this.studNum = studNum;
++numOfStudents;
}
public String toString() {
return "(" + name + ", " + studNum + ", " + numOfStudents + ")";
}
}
________________________________________________________________
import java.io.*;
public class RQ800_80 {
public static void main(String args[])
throws IOException, ClassNotFoundException {
FileOutputStream outputFile = new FileOutputStream("storage.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(outputFile);
Student stud1 = new Student("Aesop", 100);
System.out.print(stud1);
outputStream.writeObject(stud1);
outputStream.flush();
outputStream.close();
Student student = new Student("Mowgli", 300);
FileInputStream inputFile = new FileInputStream("storage.dat");
ObjectInputStream inputStream = new ObjectInputStream(inputFile);
Student stud2 = (Student) inputStream.readObject();
System.out.println(stud2);
inputStream.close();
}
}
Which statement about the program is true? Select the one correct answer.
|