What is "static" that precedes a java variable? I thought. .. ..
To explain in words, "variables associated with the original class field".
public class car{
static int num_car = 0;
String type;
String color;
Car(String type,String color){
this.type = type;
this.color = color;
num_car++;
}
}
When there is code like this, "type" and "color" are unique to the instance field, but since "num_car" is the number of instances, it is linked to the car class field itself and updated steadily. Things to go.
Recommended Posts