File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Access modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Access modifier" Watch "Access modifier" New topic
Author

Access modifier

Sunita Vontel
Ranch Hand

Joined: Aug 28, 2000
Posts: 72
A class design requires that a particular member variable must be accessible for direct access by any subclasses of this class, but otherwise not by classes which are not members of the same package.
What should be done to achieve this?
A.The variable should be marked public
B.The variable should be marked private
C.The variable should be marked protected
D.The variable should have no special access modifier
E.The variable should be marked private and an accessor method provided
I thought the answer is D but it is C. If the variable is marked protected it can be accessed by subclasses outside the package right.
Please clarify
Sandeep Potnis
Ranch Hand

Joined: Aug 18, 2000
Posts: 39
The answer is in the question.
Sandeep
Sunita Vontel
Ranch Hand

Joined: Aug 28, 2000
Posts: 72
hi Sandeep
The question says the variable should not be accessed from other packages but if the variable is protected it can be acessed from other packages right??
I said C coz of u dont have any modifier it has friendly scope and can be accessed only in the same package.
Am i right??
Sandeep Potnis
Ranch Hand

Joined: Aug 18, 2000
Posts: 39
Sunita,
This is the question:
A class design requires that a particular member variable must be accessible for direct access by any subclasses of this class, but otherwise not by classes which are not members of the same package.
What should be done to achieve this?
This means,
If subclass in any package
Have direct access
Else (otherwise)
Package access.
This is also the definition of protected access.

hth
Sandeep
Sunita Vontel
Ranch Hand

Joined: Aug 28, 2000
Posts: 72
Thanks Sandeep
 
 
subject: Access modifier
 
Threads others viewed
Protected Modifier....
question from jargon
Sun Sample Question - Access Modifier
Sample Question from Sun site
Protected Vs Default
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture