Question: Which lines can the of the following program print out?
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 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. empty line
C. 2009
D. 0
E. Channel@1540e19d
F. null
G. The code does not compile
H. The code compiles but throw exceptions at runtime
Next Question
No comments:
Post a Comment