-1
class Box
{
// Instance Variables
double length ,ipsos ;
double width ,mikos ;
double height ,platos;
// Constructors
 public Box ( double side )
{
width = side ;
height = side ;
length = side ;
}
public Box ( double x , double y , double z)
{
    platos = y ;
ipsos = z;
mikos = x ;

}

// Methods
double calculate(double praksi)
{
return 2 * ( width * height +
width * length +
height * length ) ;
}
double volume(double emvadon)
{
return platos*ipsos*mikos ;
}

@Override
public String toString() {
    return "Volume: " + volume(1) + "\n Calculate: " + calculate(1);
}
public class Cube extends Box {
    public Cube(double side) {
        super(side, side, side);
        if (side<0) { System.out.println("lathos timi");} 
    }

public void calculate2(double z )
{super.calculate( z  );}
public void volume2(double y)
{super.volume( y );}
@Override
public String toString() {
    return "Volume: " + super.volume(1) + "\n Calculate: " + super.calculate(1);
}


}
public class Spirtokouto extends Box {
    public Spirtokouto(double side) {     
        double weight;
        super(side, side, side,side);

    }

}

}

ONLY THE LAST PART MATTER ( i mean i got problem only with this)

When i compile this, i get no suitable constructor error. why is this?? By the way the purpose of the Spirtokouto class, is to put one more value for count (the weight ) . Can i extend one class to >1 classes?

1 Answers1

5

The Box class two constructors: public Box ( double side ) and public Box ( double x , double y , double z) but none of them takes four parameters, and your calling it with four so change this:

 public Spirtokouto(double side) {     
        double weight;
        super(side, side, side,side);    
    }

to this:

 public Spirtokouto(double side) {     
        super(side, side, side);    
        double weight;
    }

The call to super must come first in the constructor.

Can i extend one class to >1 classes?
If you mean if one class can inherit from multiple classes, the answer is no in Java. You can however have a class implement multiple interfaces, but that's a different thing.

jpw
  • 44,361
  • 6
  • 66
  • 86