![](/img/trans.png)
[英]How can I subclass (extend) a Java class using Rhino when I need to use a constructor that takes an argument?
[英]Java - How can I use a 3 argument constructor to set 2 instance variables
好的,所以我想通了。 構造函數應該是這樣的:
public Circle(double x, double y, double radius)
{
center = new Point(x, y);
this.radius = radius;
}
該圖表明Circle
和Point
之間的關系是一個組合。
所以相關的java代碼是:
public class Circle
{
private double radius;
private Point center;
public Circle(double x, double y, double radius)
{
this.radius = radius;
center = new Point(x, y);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.