I was learning the basics of Java IO, and I saw that to use a user-defined function writeObjectin a class, it must be declared private.
private void writeObject(ObjectOutputStream oos);
Then when we call
oos.writeObject(myClassObject);
This function searches for the private writeObject method in MyClass and executes it.
My question is: if this is true, then will it not be a violation of the concept of data abstraction when a function can call a private method of another class? What is the reason for this feature?
source
share