aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Access Modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Access Modifiers" Watch "Access Modifiers" New topic
Author

Access Modifiers

rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
hi,

Top level classes can be declared as public or they can be default. They can't be protected. Why is this so? When they can have default access modifier(friendly) which is more restricted than protected why can't they have their access modifier as protected?
rajani
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I am moving this to Programmer Certification Study as it is more suited to that area as opposed to Mock exam erratas.
Bill
rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
thanks bill...i posted it in the exam erratas by mistake
Edy Yu
Ranch Hand

Joined: Nov 21, 2000
Posts: 264
"protected" can only be used to methods, variables and inner classes.


SCJP, SCJD, SCWCD, SCBCD, SCEA, IBM Certified Enterprise Developer, WebSphere Studio V5.0
Oliver Grass
Ranch Hand

Joined: Nov 02, 2000
Posts: 65
Hi Rajani,
i don't know if you're satisfied with this answer but this behavior is defined in the Language specification. You have to accept this...
hope that helps
cheers
Oliver
Nasir Khan
Ranch Hand

Joined: Nov 04, 2000
Posts: 135
if a class 'x' of package 'p' has a default access modifier then there's no point having a protected method 'm' with 'x'
because in another package we can't access class 'x' so how can we access 'm' .So my conclusion is that
a class should be public(although not enforced by java) if its is declaring some protected members.
please someone tell me if my conclusion is wrong.

Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
A class needs to access within a package or outside it.
So, default access will do for package access & public will do for outside package access. So, under what cicumstance would we need a protected modifer for??
Also, nasir, I do not agree with your view. Please have a loo at this and I hope u'll get clarified http://www.javaranch.com/ubb/Forum24/HTML/003727.html

- Sathvathsan Sampath
Nasir Khan
Ranch Hand

Joined: Nov 04, 2000
Posts: 135
Thanks Sathvathsan
you realy helped by giving me old post by sampaths77.
What I extracted from that is
Even a class 'x' has a default access modifier its public or protected members can be accssed by another class in another package if x extends a public class .
rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
thanks all...my doubt is cleared
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access Modifiers