aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from JQPlus :: Please help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from JQPlus :: Please help." Watch "Question from JQPlus :: Please help." New topic
Author

Question from JQPlus :: Please help.

Purvesh Vora
Ranch Hand

Joined: Dec 10, 2003
Posts: 47
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
Rama Kumar PV
Greenhorn

Joined: Dec 26, 2003
Posts: 26
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Question from JQPlus :: Please help.