下列ABCD注释标注的哪行代码有错误? class Tom { private int x = 120; protected int y = 20; int z = 11; private void f() { x = 200; System. out. printIn (x); } void g() { x = 200; System. out. println (x); } } public class E { public static void main (String args[]) Tom tom = new Tom(); tom. x = 22; //A tom. y = 33; //B tom. z = 55;//C tom. g () ; //D } }
时间: 2024-02-14 18:11:03 浏览: 120
该段代码有一个语法错误,应该在 main 方法的第五行末尾加上 `{`,正确代码如下:
```java
class Tom {
private int x = 120;
protected int y = 20;
int z = 11;
private void f() {
x = 200;
System.out.println(x);
}
void g() {
x = 200;
System.out.println(x);
}
}
public class E {
public static void main(String args[]) {
Tom tom = new Tom();
tom.x = 22; //A
tom.y = 33; //B
tom.z = 55; //C
tom.g(); //D
}
}
```
这样就可以通过编译了。
阅读全文