wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Access modifier question from Khalid's mock exam 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 question from Khalid Watch "Access modifier question from Khalid New topic
Author

Access modifier question from Khalid's mock exam

Sahir Shah
Ranch Hand

Joined: Nov 05, 2000
Posts: 158

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 ?


....
naveen sahu
Ranch Hand

Joined: Nov 15, 2000
Posts: 48
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)
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

in case you still dont know it is answer 5


SCJP
Visit my download page
James Inge
Greenhorn

Joined: Dec 04, 2000
Posts: 12
I would have thought 2 & 5. Declaring the method as protected gives it package only restriction the same as no modifier.
Am I wrong?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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).]


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
S Sivasuthan
Greenhorn

Joined: Nov 29, 2000
Posts: 6
Protected members of the class are accessible to all the classes in the same package like default.
Regards
Siva
Originally posted by Thomas Paul:
No. Protected means only classes that extend that class would have access. The correct answer is 5.

Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
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.
Amit Goel
Ranch Hand

Joined: Dec 07, 2000
Posts: 50
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
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
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://aspose.com/file-tools
 
subject: Access modifier question from Khalid's mock exam
 
Similar Threads
que on voodooexam
class modifiers and other stuff
null is a Java Keyword?? - Java Doc??
Constructors and interfaces
static variables declaration