use*_*799 7 java oop constructor
考虑我们有两个类Line
,Point
哪个类使用类Point
如下:
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
Run Code Online (Sandbox Code Playgroud)
和
public Class Line
{
private Point start;
private Point end;
...
}
Run Code Online (Sandbox Code Playgroud)
我想知道由于OOP原则,下面哪个构造函数更适合类Line?
public Line(Point start, Point end)
{
this.start = start;
this.end = end;
}
Run Code Online (Sandbox Code Playgroud)
要么
public Line(int startX, int startY, int endX, int endY)
{
start = new Point(startX, startY);
end = new Point(endX, endY);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
120 次 |
最近记录: |