当我使用对象时,在java中找不到符号

时间:2017-07-28 10:41:28

标签: java

当我在命令提示符下执行它时,它会给高度找不到符号

的错误
class vol {
       int height;
       int width;
       int length;
}

class box {
      public static void main(String args[]) {
         vol mybox = new vol(); // mybox is created as a object
         mybox.height = 10;
         System.out.println(height);
      }
}

2 个答案:

答案 0 :(得分:1)

class Vol {          
    int height;
    int width;
    int length;
}

class Box {
    public static void main(String args[]) {
        Vol mybox = new Vol();             //mybox is created as a object
        mybox.height = 10;
        System.out.println(mybox.height);
    }
}

试试这个。

答案 1 :(得分:0)

问题在于System.out.println(height);行。它应该是System.out.println(mybox.height);