File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question from JQPlus :: Please help.
 
Similar Threads
please help!- what is the result of this code
private member
Satou kurinosuke i have one more question for you
Object Passing By Reference
Satou kurinosuke i have one more question for you