Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Difference between protected and blank method

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the answer for this:
1)What access control keywork should you use to
allow other classes to access a method freely within its package,but to restrict classes
outside of the package from accessing that method.
a)public
b)protected
c)private
d)do not supply access control keyword

2)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
 
Trailboss
Posts: 23315
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taylor,
Do you post these questions because there is something you would like clarification on?
Or, so you post them here so that other people who might also be studying can consider them?
If you are looking for clarification, it would help if you pointed out what part of the question confuses you.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the answer to the first question is
blank - no modifier
the answer to the second question is
protected
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i agree with sona ...
1.) blank
2.) protected
but taylor what is your doubt?
looking at the title i presume ur doubt i the difference b/t the protected access modifier and the default access modifier.

well basically the members with the default access modifier have packge level scope i.e they can be accessed directly only within the package whereas protected members go one step further and also allow direct access from a different package subclass of the class having the protected member
have a look at the following code for an example for direct protected member access

hope that helps
Samith.P.Nambiar
<pre>
\```/
(o o) harder u try luckier u get
-------oOO--(_)--OOo----------------------------
</pre>
 
Ranch Hand
Posts: 1874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taylor , Welcome to javaranch.
PROPER NAMES ARE NOW REQUIRED
Please look carefully at official naming policy at javaranch & reregister yourself with proper first & last name. Please adhere to official naming policy & help maintain the decorum of the forum.
Waiting for your posts with proper first & last name. Once you have reregister , please let us know about that & then your previous account will be disabled.
Regards.

Your Friendly Bartender
Shailesh.

[This message has been edited by shailesh sonavadekar (edited June 02, 2001).]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic