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
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;
}
}
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
}
}