序列化继承(转)

    xiaoxiao2021-12-14  58

    public class SerializableEr implements Serializable{      /**      *      */      private static final long serialVersionUID = 1L;       }  public class Serial extends SerializableEr {      int id;      String name;      public Serial(int id, String name) {          this.id = id;          this.name = name;      }      public String toString() {          return "DATA: " + id + " " +name;        }      public static void main(String[] args) {          Serial serial=new Serial(1,"4234");          System.out.println("object serial:"+serial);           try{              FileOutputStream fos=new FileOutputStream("serialTest.txt");              ObjectOutputStream oos=new ObjectOutputStream(fos);               oos.writeObject(serial);               oos.flush();               oos.close();           }catch(Exception e){              System.out.println("Exception:"+e);           }      }  }  为一个实现Serializable接口的父类,编写一个能够序列化的子类 子类将自动的实现序列化
    转载请注明原文地址: https://ju.6miu.com/read-965065.html

    最新回复(0)