• Post Reply Bookmark Topic Watch Topic
  • New Topic

public variables  RSS feed

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

I'm having hard times with variables between the classes. I give you an example:



So the "cannot resolve symbol" error comes in docMakerFrame class on this row:
filename="test";

and in htmlMaker constructor.


I don't understand why String filename is not accessable. Seems to me i give all the access rights.
 
Darin Niard
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classes don't share members with each other unless there is an inner/outer relationship, and of course in the case of inheritance.

All classes DO have access to your "filename" variable, ie, docMaker.filename is available for use.
[ August 03, 2004: Message edited by: Darin Niard ]
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code should be as follows:

 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The concept is, you access static members of a class using the class name. Now the variable filename is a static member and therefore, it will have to be accessed in other classes by using the name of the class in which it is declared. Hence the syntax:

docMaker.filename;

Got it?
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you .. now it's very clear. It's been a while since i used java and oo. language now i remember.
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making attributes non-private always rubs me the wrong way. I use getters and setters when I need to access private variables.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!