62,614
社区成员
发帖
与我相关
我的任务
分享
import java.lang.Exception;
import java.io.*;
public class ReadTeacher {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: 在这添加你的代码
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream("teacher.txt"));
Teacher t1;
try {
t1 = (Teacher) ois.readObject();
Teacher t2 = (Teacher) ois.readObject();
Person p = (Person) ois.readObject();
Teacher t3 = (Teacher) ois.readObject();
System.out.println("t1:" + (t1.getStudent() == p));
System.out.println("t2:" + (t2.getStudent() == p));
System.out.println("t2与t3" + (t2 == t3));
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (ois != null)
ois.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
class Person{}
class Teacher extends Person{
public Person getStudent() {
return null;
}}