how to make variables in constructor seen by the rest of the class?

say i have something like

publicclass OrderCars{

staticint DEFAULT_SIZE = 5;

public OrderCars(int cars){

cars = cars+1;

}

publicboolean execute (int holdingtracks){

//do something here with the cars int

returntrue;

}

}

is it possible to make cars be seen by the execute method?

Message was edited by:

s34nsm4111

[953 byte] By [s34nsm4111a] at [2007-10-3 8:26:07]
# 1

Create a member variable and store the cars value there.

public class OrderCars {

static int DEFAULT_SIZE = 5;

private int cars;

public OrderCars(int cars) {

this.cars = cars+1;

}

public boolean execute (int holdingtracks){

//do something here with the cars int

// cars is accessible

return true;

}

}

hunter9000a at 2007-7-15 3:32:27 > top of Java-index,Java Essentials,New To Java...
# 2
Hi,You should create an attribute for cars. The execute method can then access that attribute.Kaj
kajbja at 2007-7-15 3:32:27 > top of Java-index,Java Essentials,New To Java...
# 3
Simply declare the 'cars' variable outside of the Constructor.
bckrispia at 2007-7-15 3:32:27 > top of Java-index,Java Essentials,New To Java...
# 4

yes

public class OrderCars {

static int DEFAULT_SIZE = 5;

int myCars;

public OrderCars(int cars) {

cars = cars+1;

myCars = cars;

}

public boolean execute (int holdingtracks){

//do something here with the cars int

if(myCars > 1)

return true;

return false

}

}

mkoryaka at 2007-7-15 3:32:27 > top of Java-index,Java Essentials,New To Java...
# 5
> is it possible to make cars be seen by the execute method?<looking around for the hidden camera/>Store it in an instance field.
Lokoa at 2007-7-15 3:32:27 > top of Java-index,Java Essentials,New To Java...
# 6
thank you all so much!
s34nsm4111a at 2007-7-15 3:32:27 > top of Java-index,Java Essentials,New To Java...