Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

friend classes and variable access

Status
Not open for further replies.

Sedai

Programmer
Mar 4, 2001
158
US
I'm new to JAVA.

Is there an equivalent to C/C++ friend classes
where you can declare a certain class a friend of another, so that he has access even to its private data members?

I know about protected (same in C++) but that's not the same. I need acces from an 'unrelated' class.

Thanks a lot for your help and time. Avendeval


 
There is not a concept of a "friend" in Java. You will need to make your members public to allow access.
 
Sorry, prematurely hit submit. There is the concept of package level access also known as "default" access. If you do not specify an accessibility modifier than it has default access. Default access grants access to all subclasses and any classes that are in the same package. This is still not the same as a friend in C but it may help.
 
Inner classes are tied to a particular Outer Class. In C/C++ a friend Class could be a friend of multiple separate and entirely different classes. In this sense friends in C/C++ are not the same as any construct in Java.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top