[英]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.