• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question from jargon

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
it says right answer is c
but i think its d
any comments
thanx in anticipation
kashif

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The variable should be marked protected. This makes it available only to the subclasses.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kashif,
the answer is 'c' and here's why. When you mark a variable protected all subclasses have access to the variable.
When no access modifier is provided, the default is package, which means that a variable without an access modifier will be available to all classes within that package(may not necessarily be subclasses). Hence 'D' is a wrong choice.
Thanks
Shilpa
 
reply
    Bookmark Topic Watch Topic
  • New Topic