They are the three keywords used to define the scope of a class or method or a variable in Java. They are called access modifiers. In fact, they are four, the fourth one is «nothing» (empty, no modifier) and it is different to public.
- public : class or method or variable using this modifier can be used by any object.
- «nothing» : class or method or variable without modifier can be used by any class in the same package.
- protected : class or method or variable using this modifier can be used only by the sub classes and classes in the same package.
- private : class or method or variable using this modifier can be used only in the class where they are defined.
In general, any class or method or variable is accessible in the class where it is defined.
See also :
- Basic Concepts in Java
- What is Class, interface, and Object in Java?
- What does static mean in Java?
- What does final mean in Java?
- What does transient mean in Java?
- What does volatile mean in Java?
- Which are types of JDBC drivers?
- Cite three objects included in the JSP page
- What is servlet, what is jsp?
- What's difference between directive and action?
- Which are the struts tagLibs?
- What is Hibernate?
- What's JEE and which are their APIs?
2 comments
No ping yet
Digital SLR Reviews says:
August 21, 2011 at 5:27 pm (UTC 0)
I won’t be able to thank you fully for the articles on your web-site. I know you’d put a lot of time and energy into all of them and hope you know how much I appreciate it. I hope I could do the same for someone else sometime.
Samsung Camera Reviews
jalal mjadli says:
August 22, 2011 at 10:05 am (UTC 0)
10x