This is the question "It is desirable that a certain method within a certain class can only be accessed by classes that are defined within the same package as the class of the method. How can such restrictions be enforced?" The selection controls are radio buttons (ie: select only one) The answer options are 1. Mark the method with the keyword Public 2. Mark the method with the keyword protected 3. Mark the method with the keyword private 4. Mark the method with the keyword package 5. Do not mark the method with any access modifiers He probably will accept only one of them as the right answer. Which one is it ?
Originally posted by Sahir Shah: This is the question "It is desirable that a certain method within a certain class can only be accessed by classes that are defined within the same package as the class of the method. How can such restrictions be enforced?" The selection controls are radio buttons (ie: select only one) The answer options are 1. Mark the method with the keyword Public 2. Mark the method with the keyword protected 3. Mark the method with the keyword private 4. Mark the method with the keyword package 5. Do not mark the method with any access modifiers He probably will accept only one of them as the right answer. Which one is it ?
Sahir let suppose you are walking on a road . and at any moment you heared a sound like one of these 1) Hey Sahir 2) Hey Shah 3) Hey Sahir Shah so at which one sound you respond definately, if you are only allowed to respond only a single voice. choose the mose appropriate and then you will get the ans of your question. (because i think , you are not a person which doesn't know which modifier is most suitable)
No. Protected means that in addition to classes in the same package, classes that extend that class would also have access. The correct answer is 5. [This message has been edited by Thomas Paul (edited December 09, 2000).]
S Sivasuthan, Your contribution to Javaranch is very important to us. However we do have a naming policy outlined here. Please register again with a name which complies to this rule. Otherwise I'm afraid you may come to the Ranch soon and find that your account has been locked. Thank You. [This message has been edited by Angela Poynton (edited December 08, 2000).]
Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
in this question the answer should be 5th choice as a default specifier can do that as protected keyword is given if other classes are subclasses of the class which you define protected.
Amit<br /> <br />The Less I have, The more I gain..Off the Beaten Path, I Reign.
Sahir Shah
Ranch Hand
Joined: Nov 05, 2000
Posts: 158
posted
0
Originally posted by Thomas Paul: No. Protected means only classes that extend that class would have access. The correct answer is 5.
If so shoudn't this be illegal? <pre> class Bird{ protected void fly() { System.out.println("flap, flap, flap"); } } public class Test{ public static void main(String[] args) { Bird robin = new Bird(); robin.fly(); } } </pre>
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
My answer was misleading. What I meant to say was that protected would also allow classes that extend the class to have access which is not what the original question wanted to happen.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Access modifier question from Khalid's mock exam