• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Mock question, answer confirm please

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


25) A sample question provided by Sun

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 chose "D", answer says "C".



How is it description of protected Keith? [Post edited after Keith's reply]

Thanks,
cmbhatt
[ April 12, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The description of the problem is the definition of protected.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I got?


Error because member variable of class accesstest1.DemoTest1 is "default".
That is only accessible to subclass of the class (inner class obviously) and to the class that are in the same package.

Isn't it Keith?


Please consider,


cmbhatt
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Default access means the variable is visible only to classes in the same package and to the class itself.

Subclasses that are in other packages can't see the members that have default access.
[ April 12, 2007: Message edited by: Keith Lynn ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what about the answer.

"D" is correct?



cmbhatt
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C is correct.

The variable

must be accessible for direct access by any
subclasses
of this class

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still confusing,

What direct access means?

:roll: :roll:

Please make it clear!!!


Regards,
cmbhatt
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandra,

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?

1)any subclasses: Means it belongs to same package or Outer package.
2)but otherwise not : Now he is going to say about classes which are not subclasses.
2.1)which are not members of the same package.:
Outer classes which are not subclasses should not access that variable.

I think you missed point two.
Hope this will help you proceed.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Srini,

You are correct, I missed the second point.
"But otherwise not" these three words fried my brain while answering the mock.


Thanks again!
cmbhatt
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic