当前位置: 代码迷 >> Eclipse >> 能否在static方法中调用非静态方法?解决办法
  详细解决方案

能否在static方法中调用非静态方法?解决办法

热度:89   发布时间:2016-04-23 18:46:48.0
能否在static方法中调用非静态方法?
初学,想求一段示例。

------解决方案--------------------
不能调用非静态变量,非静态方法嘛,不清楚,你试试能否编译?能编译应该就可以
------解决方案--------------------
更改我的说法,不好意思,main函数就是STATIC静态的嘛
看:
public class StaticDemo {

/**
* @param args
*/
public int add()
{
return 2;
}

public static void main(String[] args) {
// TODO 自动生成方法存根
System.out.println(new StaticDemo().add());
}

}
  相关解决方案