File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes access modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "access modifier" Watch "access modifier" New topic

access modifier

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?
1. public
2. abstract
3. protected
4. default access

Ans: (4) default access

why not also protected. When we are talking about same package both default access and protected are equally restrictive.
It's only when we talk abt 2 different packages, protective is less restrictive than default.
But ques explicitly states same package, so shouldn't it be both default and protected.
please suggest.
Linus Nikander

Joined: May 21, 2004
Posts: 9
I think that they, by asking you to pick out the most restrictive modifier, are looking for the modifier which has the most restrictive properties OVERALL which will still fulfill the requirement of allowing you to access it from within the same class. In a comparison of overall properties, default is more restrictive than protected.

I agree with you that the question is somewhat ambiguous though, and that your interpretation is fully correct. I just don't think that it?s what they meant when they wrote it.
Wendal Park
Ranch Hand

Joined: Aug 28, 2001
Posts: 39
Well, from my perspective, the usage of the word MOST refers to one and only one choice. So it's got to be the default access modifier.

MSc, BSc, SCJP 1.4<br /> <img src="graemlins/banghead.gif" border="0" alt="[banghead]" /> SCBCD
I agree. Here's the link:
subject: access modifier
It's not a secret anymore!