B
bagarow
Hi
In the following code fragment:
class Cups {
static int cupCount = 10;
Cups () {
System.out.println ("Cups");
// Would like to create a array of cup objects here
}
}
public class Cuppas2 {
public static void main (String[] args) {
System.out.println("Inside main");
System.out.println("Cup Count is " + Cups.cupCount);
}
}
The constructor for class Cups does not get executed when the static
field Cups.cupCount is referenced in the main method print statement.
If in the initialization of the class Cups, I wanted to use a non
simple code fragment e.g. creating an array of objects with a for loop,
is there a way to do that in the client code without calling new
Cuppas2()?
Thanks
Bob
In the following code fragment:
class Cups {
static int cupCount = 10;
Cups () {
System.out.println ("Cups");
// Would like to create a array of cup objects here
}
}
public class Cuppas2 {
public static void main (String[] args) {
System.out.println("Inside main");
System.out.println("Cup Count is " + Cups.cupCount);
}
}
The constructor for class Cups does not get executed when the static
field Cups.cupCount is referenced in the main method print statement.
If in the initialization of the class Cups, I wanted to use a non
simple code fragment e.g. creating an array of objects with a for loop,
is there a way to do that in the client code without calling new
Cuppas2()?
Thanks
Bob