没有合适的构造函数 [英] No Suitable Constructor

查看:62
本文介绍了没有合适的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

当我编译它时,没有合适的构造函数错误.为什么是这样??顺便说一下,Spirtokouto类的目的是要增加一个计数值(权重).我可以将一个班级扩展到> 1个班级吗?

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?

推荐答案

Box类的两个构造函数: public Box(double side) public Box(double x,double y,doublez),但是它们都不带四个参数,而您要用四个参数来调用它,因此请更改此参数:

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);    
    }

对此:

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

super 的调用必须首先在构造函数中.

The call to super must come first in the constructor.

我可以将一个班级扩展到> 1个班级吗?
如果您是说一个类可以从多个类继承,那么在Java中答案是否定的.但是,您可以让一个类实现多个接口,但这是另一回事.

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.

这篇关于没有合适的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆