SCJP一道选择题,为什么CardPlayer c2 = (CardPlayer) is.readObject();单独创建父类对象?

代码如下:

class Player {
 Player() {
  System.out.print("p");
 }
}

public class CardPlayer extends Player implements Serializable {
 CardPlayer() {
  System.out.print("c");
 }

 public static void main(String[] args) {
  CardPlayer c1 = new CardPlayer();
  try {
   FileOutputStream fos = new FileOutputStream("play.txt");
   ObjectOutputStream os = new ObjectOutputStream(fos);
   os.writeObject(c1);
   os.close();
   FileInputStream fis = new FileInputStream("play.txt");
   ObjectInputStream is = new ObjectInputStream(fis);
   CardPlayer c2 = (CardPlayer) is.readObject();
   is.close();
  } catch (Exception x) {
  }
 }
}

为什么最后输出结果是“pcp”而不是“pcc”?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问