global variable

F

Frank

Hello,

How can I set a variable in a class to be global so that my packages
can work with it?

Example:
I have a project game in folder mygame. The main class is called
Tetris.java. Inside the same directory I have a package called
myframes with the frames used to interact with the user. the class
Tetris has the following variable declared:

public class Tetris
{
public static int langType = 1;

....

}

Why classes inside my package myframe cannot see this variable?
Thanks.

Frank
 
V

VisionSet

Frank said:
public class Tetris
{
public static int langType = 1;

....

}

Why classes inside my package myframe cannot see this variable?
Thanks.

They should be able to, as long as you import the package.
Then Tetris.langType will reference it.
Consider making it final or using get/set methods to access it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top