I have a class that has a private static variable,
private static counter = 0;
but it gives an error when I compile it:
Car.java:3: <identifier> expected
private static counter = 0;
^
Does anyone know why it does this? I don’t understand what’s wrong with it.
Here’s the whole code:
public class Car
{
private static counter = 0;
private String name;
public Car()
{
name = "car" +counter;
counter++;
}
}
You forgot the type. It seems that you mean
private static int count = 0;