0

在此页面上的示例中:http ://www.scala-lang.org/node/125

class Point(xc: Int, yc: Int) {
  val x: Int = xc
  val y: Int = yc
  def move(dx: Int, dy: Int): Point =
    new Point(x + dx, y + dy)
}

class ColorPoint(u: Int, v: Int, c: String) extends Point(u, v) {
  val color: String = c
  def compareWith(pt: ColorPoint): Boolean =
    (pt.x == x) && (pt.y == y) && (pt.color == color)
override def move(dx: Int, dy: Int): ColorPoint =
  new ColorPoint(x + dy, y + dy, color)
}

扩展类上的参数/参数列表在子类的定义中起到什么作用?我指的是行(u, v)尾的。Pointclass ColorPoint(u: Int, v: Int, c: String) extends Point(u, v) {

4

1 回答 1

3

如果您熟悉 Java,则此代码将是相同的:

class ColorPoint extends Point {
  ColorPoint (int u, int v, String c) {
    super(u,v);
  ...
  }
  ...
}

所以,是的,它是对 super 的构造函数的调用

于 2012-09-27T10:44:39.950 回答