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 void serialize() {}
8 public String getBrand() {return this.brand;}
9 public void setBrand(String brand) {this.brand = brand;}
10 public int getYear() { return year;}
11 public void setYear(int year) { this.year = year;}
12 public Channel getChannel() { return channel;}
13 public void setChannel(Channel channel) {this.channel = channel;}
14
15 public static void main(String[] args) throws IOException {
16 try(ObjectOutputStream out = new ObjectOutputStream(
17 new BufferedOutputStream(new FileOutputStream("tv.dat")))) {
18 TV tv = new TV();
19 tv.setBrand("jee");
20 tv.setYear(2009);
21 tv.setChannel(new Channel());
22 out.writeObject(tv);
23 }
24 }
25 }
Choice:
A. The code compiles and runs without any problem.
B. A compile error at line 2
C. A compile error at line 7
D. A compile error at line 16-17
E. A compile error at line 20
F. A compile error at line 22
G. The code compiles but throws Exception at runtime.
No comments:
Post a Comment