test12.java
来自「SCJP认证考试资料」· Java 代码 · 共 39 行
JAVA
39 行
import java.io.*;
class B{
int i = 2;
B(int i) {
this.i = i;
}
B() {
}
}
class A extends B implements Serializable {
int x = 5;
A(int x) {
super(x);
this.x = x;
}
}
class Test12{
public static void main(String[] args) throws Exception{
File f = new File("a.txt");
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream(f));
oos.writeObject(new A(5));
oos.close();
ObjectInputStream ois = new ObjectInputStream(
new FileInputStream(f));
A obj = (A)ois.readObject();
System.out.println(obj.i);
ois.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?