下列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. print]n (x); public class E { public static void main (String argsl Tom tom = new Tom); tom. x = 22; /A tom. y = 33; //B tom. z = 55; TIC tom. g () ; //D
时间: 2023-12-03 17:03:48 浏览: 245
代码中有两处错误,第三行应该是 public class Tom 而不是 class Tom,第九行应该是 new Tom() 而不是 Tom)。正确代码应该是:
```java
public 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
}
}
```
相关问题
挑错题(ABCD注释标注的哪行代码有错误?) class OutClass { int m = 1; static float x; //A class InnerClass { int m =12; //B static float n =20.89f;//C InnerClass(){ } void f() { m = 100; } } void cry() { InnerClass tom = new InnerClass(); //D } }
在给出的代码中,注释标注的行C有错误。
在内部类中,静态成员变量是不允许的。因为内部类是与外部类的实例相关联的,它不能拥有静态成员。所以在行C中,将静态关键字应用于内部类的成员变量n是错误的。
正确的代码应该是:
```java
class OutClass {
int m = 1;
static float x;
class InnerClass {
int m =12;
InnerClass(){
}
void f() {
m = 100;
}
}
void cry() {
InnerClass tom = new InnerClass();
}
}
```
阅读全文