• 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 JQPlus :: Please help.

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider this class:
class A
{
private int i;
public void modifyOther(A a1)
{
a1.i = 20; //1
}
}
State whether the following statememnt is true or false:
At //1 a1.i is valid.



Select 1 correct option.
a True
b False

The answer is True. How?? Its compiling fine.
Please explain in details
Thanks & Regards,
Purvesh
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Purvesh,
The private keyword means that no one can access that member except the methods of that class. So, a private modifier can only curb the member access from external classes and not to the members within including the inner classes and other methods.
For example, If you create another class B with a private member j in it and instantiate it in class A, you will not be able to access j from class A where as you will be able to access i from within A from all the methods.
Rama
 
reply
    Bookmark Topic Watch Topic
  • New Topic