aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confusion" Watch "Confusion" New topic
Author

Confusion

Doit
Ranch Hand

Joined: Aug 03, 2000
Posts: 169
In the following code which defines the class BigWidget as extending Widget,the xxxxx
stands for an access modifier for the method SetWidth.
1)public class Widget extends Object {
2) protected static final int maxWidth = 40;
3) private int myWidth;
4) xxxxxxx void SetWidth(int n) {
5) myWidth = n;
6) }
7)}
8)class BigWidget extends Widget {
9)BigWidget() {
10) SetWidth(maxWidth * 4);
11) }
12)}
Which of the following modifiers, used in line 4 instead of xxxxxxx would allow the Big
Widget class to access the SetWidth method(as in line 10) but prevent unrelated classes in
other packages from calling SetWidth?
1)protected
2)blank-i.e the method declaration would read void SetWidth(int n)
3)private
4)public
I would select 1 and 2 as the question only asks unrelated classes in other packages but not related classes, so if it is protected related(sub) classes can access,if i say blank can not beaccesed by both related and unrelated classes. What do u guys think? What should we do in the exam if we get such questions?
- Thanks
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I think it will be protected only. If it's blank then related classes(sub classes) in other packages cannot access the method.
Thanks,
BS
Praveen Kesani
Greenhorn

Joined: Jul 05, 2000
Posts: 24
Default modifier is friendly and it allows access within the package. I was confused with this one too!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Confusion
 
Similar Threads
Sierra/Bates SCJP v6 - Interfaces and overridden methods
Exam Cram Question 34
Ques on Access Specifiers
About conversions and access modifiers
Difference between protected and blank method