Yes. There is a difference!
For example, say that you want each object in your application to save its creation time. You want all inheritors of Object to be able to read their OWN creation time, but you DO NOT want other objects to be able to read the creation time of their peers.
You can provide this encapsulation protected.
Each subclass, no matter how far down the chain, can access its creation time using the expression: this.timeOfCreation. Other objects will not be able to access, someOtherObject.timeOfcreation.
But, if you make timeOfCreation public, then ALL objects can read the creation time of other objects simply through the expression: someOtherObject.timeOfCreation. Now the creation time is not encapsulated / hidden at all!
So protected is always useful if you want to store sensitive information in an instance of a class and all its children. Publishing is useful if you don't care who can see the information inside the class. (for example, if you do not want data privacy)
source share