我刚开始学习java,所以现在我读到了继承这样的可能性,所以尝试创建必须创建对象的类-box。并使用继承为创建的对象实现新属性。我尝试将每个类放在单独的文件中,因此在创建类后,尝试在
public static void main(String[] args)
所以类继承:
public class Inheritance {
double width;
double height;
double depth;
Inheritance (Inheritance object){
width = object.width;
height = object.height;
depth = object.depth;
}
Inheritance ( double w, double h, double d){
width = w;
height = h;
depth = d;
}
Inheritance (){
width = -1;
height = -1;
depth = -1;
}
Inheritance (double len){
width=height=depth=len;
}
double volumeBox (){
return width*height*depth;
}
class BoxWeight extends Inheritance {
double weight;
BoxWeight (double w, double h, double d, double m){
super(w,h,d);
weight = m;
}
}
但是,当我尝试在主类中使用 BoxWeight 时,在使用过程中出现错误
public class MainModule {
public static void main(String[] args) {
Inheritance.BoxWeight mybox1 = new Inheritance.BoxWeight(9, 9, 9, 9);
....
错误 - 没有可访问类型 Inheritance 的封闭实例。我哪里错了?