static 方法里只能访问 static变量       a不是static         
正确代码如下public class Animal {
    static int a = 90;
    static float b = 10.98f;
    public static void main(String args[]){
        float c = a+b;
        System.out.println("c = " + c);
         
    }
}

解决方案 »

  1.   

     无法从静态上下文中引用非静态 变量 a
    public class Animal {
        static int a = 90;
        static float b = 10.98f;
        public static void main(String args[]){
            float c = a+b;
            System.out.println("c = " + c);
             
        }

      

  2.   

    楼上正解,静态方法调用属性,只能直接调用静态属性;非静态属性必须通过对象引用才能调用。当然在调用非静态方法也是如此。public class Animal {
        int a = 90;
        static float b = 10.98f;
        public static void main(String args[]){
         Animal animal = new Animal();
            float c = animal.a+b;
            System.out.println("c = " + c);
        }

      

  3.   

    static的原因 你的a不是静态的
      

  4.   

    楼上正解。static是基于类的,而你的int a的a是基于对象的。你这里没有实例化对象,所以不能访问a。
      

  5.   

    楼上正解,static 类中访问 非static外部属性时,要不基于类来访问(A.xxxx),要么要把外部变量写为static (static int xxx);
      

  6.   

    静态方法不能访问非静态变量,你的a值是非静态的,你改成用static来修饰int a就解决了这个问题!亲
      

  7.   

    楼上都是正解 static修饰的float b 是类级别的变量 在JVM创建这个类的时候 就会初始化并对b赋值 而a变量则是属于对象级别的 只有在new Animal类的时候才会被初始化并赋值