如上是经典的Fobonacci递归算法:
public class Fibonacci
{
public static void main(String []args)
{
int x = f(6);
System.out.println(x);
}
public int f(int x)
{
if(x==1||x==2)
return 1;
else
return f(x-1)+f(x-2);
}
}
编译后出错,无法在静态上下文中引用非静态。
原来,在静态的方法中不能直接调用非静态的方法或属性。因为