[英]error with a private static variable
我有一個具有私有靜態變量的類,
private static counter = 0;
但是在編譯時會出現錯誤:
Car.java:3:預期<identifier>
private static counter = 0;
^
有誰知道為什么這樣做? 我不明白這是怎么回事。
這是整個代碼:
public class Car
{
private static counter = 0;
private String name;
public Car()
{
name = "car" +counter;
counter++;
}
}
您需要指定變量的類型
private static int counter = 0;
你忘了類型。 看來你是說
private static int count = 0;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.