请教各位大虾:如下代码编译错误,真不知道为什么。

[复制链接]
查看11 | 回复3 | 2005-10-30 17:05:33 | 显示全部楼层 |阅读模式
public class test3
{
private static int j=0;
private boolean methodB(int k)
{
j+=k;
return true;
}
public static void methodA(int i)
{
b = i<10 || methodB(4);
b = i<10 || methodB(8);
}
public static void main(String [] args)
{
methodA(0);
System.out.println(j);
}
}
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
b = i<10 || methodB(4);
b = i<10 || methodB(8);
b是什么,没有定义,应该是boolean吧?
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
class B is a non-static method. class A is a static method, a static method can't reference a not-static method.
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
在同一个对象中一个静态的方法, 去调用一个动态的方法, 是不行的. 因为静态的方法只有一个线程, 而动态方法有多个线程, 系统将无法决定调用那个动态线程
解决的方法是 把methodB改成静态的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行