Hi,
I wrote a class named box With a variable named volume.
This is the first class, very simple:
Then I wrote a class that inherite from Box and Sets a value to volume:
package inheritance_Ex_2; public class PlasticBox extends Box { private int length; private int wigth; private int hight; public PlasticBox(String label, int length, int wigth, int hight) { super(label); this.length = length; this.wigth = wigth; this.hight = hight; } public void setVolume () { Volume(getLength() * getWigth() * getHight()); }
But when I write main class and try to use the setVolume function its not working:
its write me that that there is no "setVolume" in Box class.
its right, there is no "setVolume" in Box class but there is "setVolume" in PlasticBox class.
I suppose that the problam is in this line:
Box plastic1 = new PlasticBox("grapes", 4, 4, 4);
and when I chage it to - PlasticBox plastic1 = new PlasticBox("grapes", 4, 4, 4);
it fix the problem but I dont understand why.