Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Access Modifiers

 
Sri Jad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam referring to the question from K&B book(for version 1.4 - page 134) ..

1. 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?
A. public
B. abstract
C. protected
D. synchronized
E. default access

and the given answer is E(page 141)

But as per the same book(127)

There are three access modifiers: public, protected, and private.
There are four access levels: public, protected, default, and private.

As per the question its access modifier , but not acces level..in that case answer should be C..Some one correct me if i'm wrong
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya even i got this same doubt.. but after seeing the answer as E then i thought that default has less scope than protected.. so i thought default is put up as the answer for that.. i am also not sure.. pls ranchers help us...
 
Sri Jad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought that default has less scope than protected..


default access level is definitely most restrictive(has less scope) than protective , but the question was most restrictive access modifier not most restrictive access level
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i guessed the answer since that default access has less scope than protected... and wat is that u have a deal with most restrictive access modifier and most restrictive access level ??? access modifiers gives the access levels right??? then wats the problem..??
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. 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?


The default (package protected) access modifier has the same visiblity as "protected" access modifier.

But, if the question ask for "class" access modifer for the top level class, then only "default" is right.
 
Sri Jad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. 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?


For a given(or specified) package both protective access modifier and dafualt access level have the same scope .the difference comes only when other packages comes into picture.So our question is limited to the same package and as per the its access modifier not access level.

This is what i understood , still i may be wrong some where.
 
K Vidhyakar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I had the same doubt . bcos default is not an access modifier. its the access level that we get when we dont include any modifiers.
In the question i was asked about the most restrictive access modifiers and not access levels. So according to me the answer is protected. but i have attended many mock exam and they to say the same answer as default for similar question.
I have appeared the exam and i got the same question and i have put the default as the answer . it was correct.i have secured 96 % in the exam.

So the anwer is Default. more suggestion are welcome.......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic