对于以下代码,我收到错误
“预期的标识符”
public class ConstructorChecking{
int a = 7;
int b=90;
String s="no";
a=a+1; // for this line I am getting the error; why can't I update the value of a?
}
答案 0 :(得分:0)
本声明:
a=a+1;
在该范围内无效
在方法或构造函数中移动它......
而不是 a = a + 1; 执行 a ++;
答案 1 :(得分:0)
您可以使用init块
int a = 7;
int b=90;
String s="no";
{
a=a+1; // for this line I am getting the error; why can't I update the value of a?
}