搜题
问题   更新时间2023/4/3 12:59:00

下面程序是否有错?如果有错试标出错误位置并指出是何种错误。
程序:
class c {
static int x = 20;
int y = 30;
static int plus() {
return x+y;
}
public static void main(String [] args ) {
int result = plus();
System.out.println(“result = “ + result);

您的答案: int y=30 因为后面的plus()方法是静态的,其中有对y的调用,所以y必须是静态的以这里改为 static int y=30;
王老师:19139051760(拨打)