给你举个例子吧
class MyTest {
static void staticMethod()
{
System.out.println("static_method is called.");
memberMethod(); //这句是错误的,他不能够访问成员方法
}
void memberMethod()
{
System.out.println("member_method is called.");
staticMethod();
}
}
编译结果:
main.java:6: 无法从静态上下文中引用非静态 方法 memberMethod()
memberMethod();
^
1 错误
温馨提示:答案为网友推荐,仅供参考