2012-10-21 55 views
0

我有一個類具有專用靜態變量,誤差的私有靜態變量

private static counter = 0; 

但它給出了一個錯誤,當我編譯:

Car.java:3:<標識符>預計

private static counter = 0; 
        ^

有沒有人知道它爲什麼這樣做?我不明白它有什麼問題。

這裏是整個代碼:

public class Car 
{ 
    private static counter = 0; 
    private String name; 

    public Car() 
    { 
    name = "car" +counter; 
    counter++; 
    } 
} 

回答

4

你忘了類型的類型。看來你的意思是

private static int count = 0;

+0

是啊,我想通了,我張貼後..大腦放屁 – user939287

5

你需要指定變量

private static int counter = 0;