Is this a legit if statement. It is a button that changes a ball colour from blue to red on a click. And also display the colour in a text field. I have experimented several methods but can't get it to work. test is an int set to 0.
I get an error about the test variable now. I declared it like this
public static final int test = 0;
03-08-2005, 04:36 AM
public access can only be specified for variables defined at class level
so you cannot define a public variable inside a method.
This goes for static variables too.
If you are not using the variable inside static methods and you have no
need for accessing the variable via the class name like:
the don't use the static either.
final 'variables' are basically the same as the c #define values,
they are final, in other words the value they receive in the define statement:
public final int x=10;
is the only value they can ever get.
So i guess your code will compile if you leave out final. As a rule you should
only define variables as final and/or static if you need the functioonality I
have mentioned above.