I have a class Car
which has a class scope variable cost, i understand that this is a bad idea in practice, just trying to understand the effects of public scope class variables.
Will cost be accessible and modifiable by all objects of class Car, references by Car.cost, throughout all class loaders, or should i be aware of circumstances where multiple copies of Car.cost
might exist? Will there be just one Car.cost
in any given circumstance?
public class Car{
public static int cost;
public Car(int cost){
cost = cost;
}
}
public static void main(String args[]){
Car car = new Car(2);
}