I had problem with this. task, I surfed a little in help section and I did it like below, but today I read whole day articles on Serialization topic, and now I rereaded this task and I commented one line in writeObject() method and one in readObject() becouse I thought that two maybe are redundant. Result is the same and everything is the same and good too? Unfortunately it's no chance Verification again and maybe you'll tell me guys if my thinking is good or wrong. I think string field nameB is only in B class which is Serializable and I think this field is for oos.defaultWriteObject() method to take care.
import java.io.*;

Find the bugs
For some reason, errors are occurring when serializing/deserializing B objects.

Find the problem and fix it.

The A class should not implement the Serializable and Externalizable interfaces.

There is no error in the B class's signature :).

There are no errors in the main method.

•	The B class must be a descendant of the A class.
•	The B class should support the Serializable interface.
•	The A class should not support the Serializable interface.
•	The A class should not support the Externalizable interface.
•	The program must execute without errors.
•	When deserializing, the value of the nameA and nameB fields should be correctly restored.

public class Solution implements Serializable {
    public static class A {

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

    public class B extends A implements Serializable {

        private String nameB;

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

        private void writeObject(ObjectOutputStream oos) throws IOException {
//            oos.writeObject(this.nameB);

        private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
            this.nameA = (String) ois.readObject();
//            this.nameB = (String) ois.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);


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

        B b1 = (B)ois.readObject();
        System.out.println("nameA: " + b1.nameA + ", nameB: " + b1.nameB);