可能重复:
"无法从静态上下文引用非静态方法"背后的原因是什么?
无法对非静态方法
进行静态引用,无法对非静态字段进行静态引用
我无法理解我的代码有什么问题.
class Two {
public static void main(String[] args) {
int x = 0;
System.out.println("x = " + x);
x = fxn(x);
System.out.println("x = " + x);
}
int fxn(int y) {
y = 5;
return y;
}
}
Run Code Online (Sandbox Code Playgroud)
线程"main"中的异常java.lang.Error:未解决的编译问题:无法对类型为2的非静态方法fxn(int)进行静态引用
java ×1