Подскажите, запутался. Может глупость спрашиваю, но переклинило здесь. У нас методы writeObject и readObject принимают потоки. Мы же в мейне передаем туда объект solution. Почему не так как здесь? solution.writeObject(objectOutputStream); Solution solution2 = (Solution) readObject(objectInputStream); А вот так .это из решения где передается объект private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); } public static void main(String[] args) { try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream) ; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream)) { Solution solution = new Solution("your.file.name"); objectOutputStream.writeObject(solution); Solution solution2 = (Solution) objectInputStream.readObject();