I was just starting to learn Java, so now I read about a feature like inheritance, so try creating a class that should create a box object. And using inheritance implements new properties for the created object. I am trying to put each class in a separate file, so after creating the class try using it in
public static void main(String[] args)
So class inheritance:
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;
}
}
But, when I try to use BoxWeight in the main class, during use I got an error
public class MainModule {
public static void main(String[] args) {
Inheritance.BoxWeight mybox1 = new Inheritance.BoxWeight(9, 9, 9, 9);
....
Error. Access to an instance of type Inheritance is not available. Where am I mistaken?
source
share