Site Search:

OCPJP Simulation Test 11

<Back to OCPJP





Question: Which lines could be print out from the following program?


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


Choice:
A. jee
B. 2009
C. 0
D. empty line
E. Channel@1429e13d
F. null
G. The code does not compile
H. The code compiles but throws exception at runtime