I understand that protected access is for inheritance even for subclass outside of superclass package.
so my question is, do you declare protected access in superclass's data or method and to access it in the subclass outside of the superclass package
you need to have a reference of the superclass, with importing superclass's package , to access data
you should extend the superclass, that way you inherit the data and the method.
Thanks for answering my question, hope it is clear what I am asking
To be able to access protected members of a class A, another class must a) be in the same package, or b) be a direct or indirect subclass of A. If a class B is not in the same package, simply having a reference is not enough; class B must extend class A (or a subclass of class A).
Second, this sounds to me like how I am using Struts 2's ActionSupport class, since I don't have my action class in the same package as the ActionSupport class (com.opensymphony.xwork2.ActionSupport). But I extend it and I get to use methods like execute(), validate() and so on.
Not quite. Those methods are public, not protected. Therefore, you can call these methods through a reference from any class. The protected static Log LOG however, can only be called from your code if you subclass ActionSupport.
Joined: Aug 05, 2007
The protected static Log LOG however, can only be called from your code if you subclass ActionSupport.
Are you saying the subclass ActionSupport needs to be in the same package (com.opensymphony.xwork2.ActionSupport)
or just any subclass extends ActionSupport can use LOG?
Access right are "incremental" - visibility is only added to. So if a class has visibility to a member, broadening the access will not remove that visibilty.
The complete overview:
private: only the class itself and its members have access
default (no access modifier): private, plus classes from the same package
protected: default, plus all direct and indirect subclasses
public: protected, plus any other class.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com