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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)