Site Search:

OCPJP Simulation Test 13

<Back to OCPJP





Question: What is the result of executing the following code?


  1 import java.io.*;
  2 class Channel implements Serializable {}
  3 public class TV implements Serializable {
  4   private String brand;
  5   private transient int year;
  6   private Channel channel;
  7   public String getBrand() {return this.brand;}
  8   public void setBrand(String brand) {this.brand = brand;}
  9   public int getYear() { return year;}
 10   public void setYear(int year) { this.year = year;}
 11   public Channel getChannel() { return channel;}
 12   public void setChannel(Channel channel) {this.channel = channel;}
 13 
 14   public static void main(String[] args) throws Exception {
 15     try(ObjectOutputStream out = new ObjectOutputStream(
 16       new BufferedOutputStream(new FileOutputStream("tv.dat")))
 17       ObjectInputStream in = new ObjectInputStream(
 18       new BufferedInputStream(new FileInputStream("tv.dat")))) {
 19       TV tv = new TV();
 20       tv.setBrand("jee");
 21       tv.setYear(2009);
 22       tv.setChannel(new Channel());
 23       out.writeObject(tv);
 24       System.out.println(((TV)in.readObject()).year);
 25     }}}


Choice:
A. 0
B. 2009
C. null
D. empty line
E. The code doesn't compile
F. The code compiles but throws Exception at runtime