public Circle(double x, double y) {
this.x = x;
this.y = y;
Circle circle = new Circle(x, y, 10);
this.radius = circle.radius;
}
same output, why can not pass;
need help
正在讨论
评论 (2)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Lisa
28 十二月 2021, 13:15
Cause you create a new object inside the constructor taking two arguments instead of calling an overloaded constructor.
Creating a new object and throwing it away right after just to be able to access an int literal is wasteful. Then you could just have written radius = 10;
Task description however ask to call another constructor from within the constructor with two parameters. And this is done using this (the reference to the current object) followed by the three arguments you intend to use -> this(x, y, 10);
0
Watch7ower
30 十二月 2021, 02:30
I see.... thanks for the reply.
0