我想从公共java类中的默认构造函数调用参数化的构造函数。
我能做到吗?
public Rectangle()
{
Rectangle(10.5f,2.5f) //this not working
}
public Rectangle(float length, float breadth)
{
code...
}
答案 0 :(得分:3)
您可以使用this
关键字。
这应该可以解决问题:
public Rectangle() {
this(10.5f, 2.5f);
}
public Rectangle(float length, float breadth) {
//code..
}