在Java中调用非静态方法当我试图调用静态类中的非静态方法时,我得到了一个错误。无法从类型回放中对非静态方法Method Name()进行静态引用我不能使方法是静态的,因为这也给了我一个错误。此静态方法无法对xInterface隐藏实例方法在另一个静态方法中有什么方法可以绕过调用非静态方法吗?(这两个方法分别在单独的包和单独的类中)。
3 回答
慕后森
TA贡献1802条经验 获得超5个赞
class demo {
public static void main(String args[]) {
demo d = new demo();
d.add(10,20); // to call the non-static method
}
public void add(int x ,int y) {
int a = x;
int b = y;
int c = a + b;
System.out.println("addition" + c);
}}添加回答
举报
0/150
提交
取消
