When i run this demo it\'s call TestBean\'s writeObject method which is private
How is it possible ?
Here is the Code:
import j
The virtual machine will automatically check to see if either method is declared during the corresponding method call. The virtual machine can call private methods of your class whenever it wants but no other objects can. Thus, the integrity of the class is maintained and the serialization protocol can continue to work as normal. The serialization protocol is always used the same way, by calling either ObjectOutputStream.writeObject() or ObjectInputStream.readObject(). So, even though those specialized private methods are provided, the object serialization works the same way as far as any calling object is concerned.
You will get more about from this article:
Discover the secrets of the Java Serialization API