Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class Test
- {
- static class A
- {
- public int i;
- public int k = 1;
- public A()
- {
- i = 2;
- }
- }
- static class B extends A implements Serializable
- {
- public int j = 3;
- public B()
- {
- j = 4;
- }
- }
- public static void main(String[] args) throws IOException, ClassNotFoundException
- {
- B b = new B();
- b.i = 5;
- b.j = 6;
- b.k = 7;
- PipedInputStream pis = new PipedInputStream();
- PipedOutputStream pos = new PipedOutputStream();
- pis.connect(pos);
- ObjectOutputStream oos = new ObjectOutputStream(pos);
- ObjectInputStream ois = new ObjectInputStream(pis);
- oos.writeObject(b);
- B b2 = (B)ois.readObject();
- System.out.printf("i: %d, j: %d, k: %d%n", b2.i, b2.j, b2.k); //i: 2, j: 6, k: 1
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement