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
posted
0
The answer is in the question. Sandeep
Sunita Vontel
Ranch Hand
Joined: Aug 28, 2000
Posts: 72
posted
0
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
posted
0
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.