Advertisement
baksatibi

Untitled

May 30th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. class Test
  4. {
  5.     static class A
  6.     {
  7.         public int i;
  8.         public int k = 1;
  9.  
  10.         public A()
  11.         {
  12.             i = 2;
  13.         }
  14.     }
  15.  
  16.     static class B extends A implements Serializable
  17.     {
  18.         public int j = 3;
  19.  
  20.         public B()
  21.         {
  22.             j = 4;
  23.         }
  24.     }
  25.  
  26.     public static void main(String[] args) throws IOException, ClassNotFoundException
  27.     {
  28.         B b = new B();
  29.  
  30.         b.i = 5;
  31.         b.j = 6;
  32.         b.k = 7;
  33.  
  34.         PipedInputStream pis = new PipedInputStream();
  35.         PipedOutputStream pos = new PipedOutputStream();
  36.  
  37.         pis.connect(pos);
  38.  
  39.         ObjectOutputStream oos = new ObjectOutputStream(pos);
  40.         ObjectInputStream ois = new ObjectInputStream(pis);
  41.  
  42.         oos.writeObject(b);
  43.  
  44.         B b2 = (B)ois.readObject();
  45.  
  46.         System.out.printf("i: %d, j: %d, k: %d%n", b2.i, b2.j, b2.k);   //i: 2, j: 6, k: 1
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement