File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Difference between Access Modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between Access Modifiers " Watch "Difference between Access Modifiers " New topic
Author

Difference between Access Modifiers

Rubina Ali
Greenhorn

Joined: Nov 12, 2001
Posts: 1
Pl tell me the difference between Access Modifiers i.g private, protected,friendly and public how we can use them in packages?.
Thankx
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Hejsan!
private: a private member can only be reached from within the class it is declared in.
friendly/default: a member with no access modifier can be reached from all classes that are in the same package/folder.
protected: same as friendly/default and, in addition, the member can be reached from any subclass in any package/folder.
public: the member can be reached from any class anywhere.

Hope this helps!
//Kaspar
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
And just a note, friendly is a Cism and is not a keyword used in Java. From what I understand, friendly and default/package access are similar but not completely identical.
Jason
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Difference between Access Modifiers