Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Friend concept in java

 
meeraa pillaii
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no 'friend' type of access in Java. The close to that is package level access.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic