public class Cal
{   static int a=10;
           int b;
  
  
  public static void main(String[] args)
    { 
      b=a;
    }
}无法从静态上下文中引用非静态 变量 b
谢了哈!!!

解决方案 »

  1.   

    public class Cal
    { static int a=10;
    int b;
    public static void main(String[] args)
    {
    Cal c = new Cal();
    c.b=a;
    }
    }
      

  2.   

    “无法从静态上下文中引用非静态变量”这句话说的很明白啊:)
    首先你要new一个Cal对象才能引用非静态变量b啊
      

  3.   

    static类型的方法只能访问static变量..
      

  4.   

    没有那么麻烦吧 如果都是静态变量不就ok了 嘿嘿public class Test { /**
     * @param args
     */ static int a = 10; static int b; public static void main(String[] args) {
    b = a;
    }}