My understanding is as follows: 1) If you implement the interface Serializable then there are a couple of things required: a) Override the readObject(ObjectInputStream in) method is this true? I previous tasks this was not the case b) Override the writeObject(ObjectOutputStream out) method is this true? In previous tasks and examples this was not the case. c) all classes involved should also be serializable and have a default (no arguments) constructor is this true? As again in previous tasks this was not always the case. 2) what really confuses is me is that when you save an object I would think you save all its fields so why are we writing in the writeObject() method nameA and not NameB? also when you want to read it back I would think again you require all fields so both nameA and NameB. Yet this is not required. why? This doesn't make sense. 3) The validator is really confusing as I passed the test just by implementing the Serializable interface for the Solution class and that is my last question. How does that work? If I serialize the class which has different innerclasses are they then all serializable?
package com.codegym.task.task20.task2018;

import java.io.*;

/*
Find the bugs

*/

public class Solution implements Serializable {
    public static class A {

        protected String nameA = "A";

        //default constructor is required
        public A() {
        }

        public A(String nameA) {
            this.nameA += nameA;
        }
    }

    public class B extends A implements Serializable {
        //it is required to overwrite the 2 methods readObject and writeObject
        //for all classes involved need to be Serializable
        //all classes involved a default constructor is required

        private String nameB;

        public B(String nameA) {
            super(nameA);
        }

        public B(String nameA, String nameB) {
            super(nameA);
            this.nameA += nameA;
            this.nameB = nameB;
        }

        //why create these 2 methods we are not using it?
        /*private void writeObject(ObjectOutputStream out) throws IOException {
            out.defaultWriteObject();
            out.writeObject(nameB);
            out.writeObject(nameA);
        }*/

        /*private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
            in.defaultReadObject();
            nameA = (String) in.readObject();
            nameB = (String) in.readObject();
        }*/
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(arrayOutputStream);

        Solution solution = new Solution();
        B b = solution.new B("B2", "C33");
        System.out.println("nameA: " + b.nameA + ", nameB: " + b.nameB);
    //should this not be a call to the writeObject in class b => b.writeObject(oos);
        oos.writeObject(b); //write object b to the ObjectOutputStream

        ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(arrayOutputStream.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(arrayInputStream);

        B b1 = (B) ois.readObject();//Read the object from the ObjectInputstream and assign it to the object (B) b1 with f
        System.out.println("nameA: " + b1.nameA + ", nameB: " + b1.nameB);
    }
}

package com.codegym.task.task20.task2018;

import java.io.*;

/*
Find the bugs

*/

public class Solution implements Serializable {
    public static class A {

        protected String nameA = "A";

        //default constructor is required
        public A() {
        }

        public A(String nameA) {
            this.nameA += nameA;
        }
    }

    public class B extends A implements Serializable {
        //it is required to overwrite the 2 methods readObject and writeObject
        //for all classes involved need to be Serializable
        //all classes involved a default constructor is required

        private String nameB;

        public B(String nameA) {
            super(nameA);
        }

        public B(String nameA, String nameB) {
            super(nameA);
            this.nameA += nameA;
            this.nameB = nameB;
        }

        //why create these 2 methods we are not using it?
        /*private void writeObject(ObjectOutputStream out) throws IOException {
            out.defaultWriteObject();
            out.writeObject(nameB);
            out.writeObject(nameA);
        }*/

        /*private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
            in.defaultReadObject();
            nameA = (String) in.readObject();
            nameB = (String) in.readObject();
        }*/
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(arrayOutputStream);

        Solution solution = new Solution();
        B b = solution.new B("B2", "C33");
        System.out.println("nameA: " + b.nameA + ", nameB: " + b.nameB);
    //should this not be a call to the writeObject in class b => b.writeObject(oos);
        oos.writeObject(b); //write object b to the ObjectOutputStream

        ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(arrayOutputStream.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(arrayInputStream);

        B b1 = (B) ois.readObject();//Read the object from the ObjectInputstream and assign it to the object (B) b1 with f
        System.out.println("nameA: " + b1.nameA + ", nameB: " + b1.nameB);
    }
}