title: How serialization works when only subclass implements serializable
body: <p><strong>Only</strong> subclass has implemented <code>Serializable</code> interface.</p>
  
  <pre><code>import java.io.*;
  
  public class NewClass1{
  
      private int i;
      NewClass1(){
      i=10;
      }
      int getVal() {
          return i;
      }
      void setVal(int i) {
          this.i=i;
      }
  }
  
  class MyClass extends NewClass1 implements Serializable{
  
      private String s;
      private NewClass1 n;
  
      MyClass(String s) {
          this.s = s;
          setVal(20);
      }
  
      public String toString() {
          return s + " " + getVal();
      }
  
      public static void main(String args[]) {
          MyClass m = new MyClass("Serial");
          try {
              ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("serial.txt"));
              oos.writeObject(m); //writing current state
              oos.flush();
              oos.close();
              System.out.print(m); // display current state object value
          } catch (IOException e) {
              System.out.print(e);
          }
          try {
              ObjectInputStream ois = new ObjectInputStream(new FileInputStream("serial.txt"));
              MyClass o = (MyClass) ois.readObject(); // reading saved object
              ois.close();
              System.out.print(o); // display saved object state
          } catch (Exception e) {
              System.out.print(e);
          }
      }
  }
  </code></pre>
  
  <p>One thing, which I noticed here is, parent class is not serialized. Then, why didn't it throw <code>NotSerializableException</code> indeed it is showing following </p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Serial 20
  Serial 10
  </code></pre>
  
  <p>Also, output differ from <code>Serialization</code> and <code>De-serialization</code>. I just only know, it is because of parent class has not implemented <code>Serializable</code>. But, If anyone explain me, what happens during object serialization and de-serialization. How it changes the value ? I'm not able to figure out, also I have used comment in my program. So, if I'm wrong at any point, please let me know. </p>