Link to home
Start Free TrialLog in
Avatar of jpking72
jpking72

asked on

variable scope

i have a package with 2 classes (main and puzzle).  i want one variable "size" to be applicable to both classes.  I've tried using the code below. How do I "pass" the variable to the other class?  i could use the constructor but I feel that is wasteful and not necessary. is there another way?  i thought public variables were available to all classes in the package.
 
public class Main {

public static int size;

public Main {
}

public static void main(String[] args) {

size = .....

}

==================

public class puzzle {


for (int i = 0; i < size; i++)...etc.
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)