I was going through the basics of Java IO and I saw that, in order to use a custom writeObject
function in a class, it has to be declared private.
private void writeObject(ObjectOutputStream oos);
Then, when we call
oos.writeObject(myClassObject);
This function looks for the private writeObject method in MyClass and executes it.
My Question is: If this is true, then won't it be a violation of Data Abstraction concept when a function can call the private method of another class? What is the reason for this feature?