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 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "access modifier" Watch "access modifier" New topic
Author

access modifier

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
Ques.
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
Greenhorn

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: http://aspose.com/file-tools
 
subject: access modifier
 
Similar Threads
Question on Access Modifiers
Ques on Access Specifiers
doubt in access modifier
Problem with Ques. #120
J2eeCertificate ques