This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Access Specifiers - a Summary Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Access Specifiers - a Summary" Watch "Access Specifiers - a Summary" New topic
Author

Access Specifiers - a Summary

krishnaraj kalimuthu
Greenhorn

Joined: Nov 04, 2000
Posts: 5
Access Control :
----------------
- Access modifiers are public, protected, private.
If nothing is provided,
default - 'friendly' - package level -
permissions are given for class/members.
public permissions are given for interface members
note : friendly is not a keyword

- Accessibitlity is different in each of the following
- within the class,
- another class in the same package,
- sub class in same package,
- another class in the another package,
- sub class in another package.
- Therefore, there are
- four types of access permissions and
- five places to test the accessibility.
- Totally 20 combinations.
- Accessibility with in the class :
- private - available
- friendly - available
- protected - available
- public - available
- Accessibility with in sub class in same package :
- private - not available
- friendly - available
- protected - available
- public - available
- Accessibility with in another class in same package :
- private - not available
- friendly - available
- protected - available
- public - available
- Accessibility with in sub class in another package :
- private - not available
- friendly - not available
- protected - available
- public - available
- Accessibility with in another class in another package :
- private - not available
- friendly - not available
- protected - not available
- public - available

- Important :
- public is more visible than protected,friendly,private
- proctected is more visible than friendly,private
- friendly is more visible than private
- private is no more visible than anything.
- while overriding,
- narrowing accessibility is not allowed.
- windening accessibility is legal.
- narrowing accessibility is
public -> protected -> friendly -> private
- widening accessibility is
private -> friendly -> protected -> public

- Access Modifier Applicability :
- Access modifiers are only applicable to
classes and class members and not method variables.

- classes :
- package level class should only be public or friendly.
- inner classes can be public, protected, friendly, and private.
- constructors :
public, protected, friendly, and private
- methods
public, protected, friendly, and private
- variables
public, protected, friendly, and private
- Class with only private constructor(s)
- this class can not be instantiated.

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
A very interesting summary, but not really apropriate to the "performance" forum. I've moved it to the "Java in General (Beginner) forum instead.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access Specifiers - a Summary
 
Similar Threads
Access Specifiers - a Summary
Protected class
general question
Protected Access (yes again..yawn!!)
my notes on JLS for any1 who needs them !!