I'm a bit confused about the whole protected thing in java. If something is protected only the classes within the same package can access it, right?
Should we use protected private attributes in a class? And if so, when?
I'm a bit confused about the whole protected thing in java. If something is protected only the classes within the same package can access it, right?
Should we use protected private attributes in a class? And if so, when?
protected
members are accessible by other classes in the same package and by classes extending the class with that member, regardless of its package.
private
members are accessible only from within the class. There is no such thing as a "protected private attribute".
The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
Source: Controlling Access of Members of a Class
For the discussion about "protected private", see this.