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 access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "access" Watch "access" New topic
Author

access

shailu kneni
Greenhorn

Joined: Feb 02, 2004
Posts: 7
If I have a variable which I declare as protected it can be accessed by only derived claases from my class as well as all those in the same package. Is that right? In that sense protected is more public than the default access where only package members can access the variables but not also the derived classes. Bit confusing.

Shails
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Hi Shailu,
Welcome to JavaRanch!
Yes, you're right, it is more public than the default. The levels in Java are
private
(default)
protected
public
The "private", "protected," and "public" levels are designed to be similar to the like-named levels in C++. Since C++ doesn't have packages, Java's "default" level is more similar to C++'s "private" than anything else. This might help you remember.


[Jess in Action][AskingGoodQuestions]
shailu kneni
Greenhorn

Joined: Feb 02, 2004
Posts: 7
Hi Ernst,
Thanks for your quick response. I am the same Shailu with the name Shailu Kommineni but for some reason it was not allowing me to login with the name so I created another handle.
I feel the access modifier "protected" is confusing. It is the most public of the modifiers only next to public.

Thanks,
Shails
Nischal Topno
Ranch Hand

Joined: Nov 24, 2001
Posts: 45
you can take the help from the following table

[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ February 05, 2004: Message edited by: Jessica Sant ]
Masha Klimenko
Ranch Hand

Joined: Feb 04, 2004
Posts: 31
Protected and default access levels are similar. The only difference
between the two is that protected members are inherited by subclasses
outside the superclass package, whereas members with default access are not. Deafult members can only be inherited by subclasses that are in the same package as superclass. Think of it this way: protected makes provisions for the kids (subclasses) outside the family (package), and default only makes provisions for the kids in the family (package).
Hope this helps.


SCJP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: access
 
Similar Threads
Is Protected Method is accessible?
Confused on protected modifier
can't access finalize() method !!!
Protected Constructors
Protected access modifier