File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access modifier

 
Angela lewis
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic