GeeCON Prague 2014*
The moose likes Java in General and the fly likes Friend concept in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Friend concept in java" Watch "Friend concept in java" New topic
Author

Friend concept in java

meeraa pillaii
Ranch Hand

Joined: Apr 19, 2008
Posts: 30
Hi,
I want to use Printable class in my program. But I have a problem in the scope of variables used in the program. How to define variables/classes as 'Friend' in my class, so that I can access the values inside other classes. I have this concept in c++, but not in java.
I have included both the classes in the same package.
A variable calculated inside the printable class during printing process, cannot be accessed in my class.

Can please someone help on this. If with little highlevel example better.

regards,
Priya
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
Meeraa,

You may want to check out this site http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html for information on access modifiers in Java.


Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
There is no 'friend' type of access in Java. The close to that is package level access.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
If your question is related to this thread, then as I tried to tell you then, your problem has absolutely nothing to do with the scope of any variable. Your variable is very much in scope when you change it, you just don't call the method that changes it when you think you do.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
GeeCON Prague 2014
 
subject: Friend concept in java