Question: What is the output of the following program?
1 import java.io.*;
2 class Pet implements Serializable {}
3 public class PetStore implements Serializable {
4 private String name;
5 private int year;
6 private Pet pet;
7 public String getName() {return this.name;}
8 public void setName(String name) {this.name = name;}
9 public int getYear() { return year;}
10 public void setYear(int year) { this.year = year;}
11 public Pet getPet() { return pet;}
12 public void setPet(Pet pet) {this.pet = pet;}
13
14 public static void main(String[] args) {
15 try(ObjectOutputStream out = new ObjectOutputStream(
16 new BufferedOutputStream(new FileOutputStream("pet.dat")));
17 ObjectInputStream in = new ObjectInputStream(
18 new BufferedInputStream(new FileInputStream("pet.dat")))) {
19 PetStore pet = new PetStore();
20 out.writeObject(pet);
21 pet = (PetStore)in.readObject();
22 System.out.println(pet.getName()+pet.getYear());
23 }}}
Choice:
A. null0
B. null
C. blank line
D. The code does not compile because of line 15-18
E. The code does not compile because of line 20
F. The code does not compile because of line 21
G. None of the above
No comments:
Post a Comment