0

In the example on this page: 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)
}

What purpose does the argument/parameter list on the extended class serve in the definition of the subclass? I am referring to the (u, v) on the end of Point in the line class ColorPoint(u: Int, v: Int, c: String) extends Point(u, v) {.

taz
  • 1,506
  • 3
  • 15
  • 26

1 Answers1

3

If you familiar with Java this code would be identical:

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

So, yes, it is call to super's constructor

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
  • Ok, I think I understand. I am very familiar with Java, C++, etc. In Scala a constructor is defined within a class signature (like in Javascript), right? Except you can also define additional constructors using `this`. So the code I asked about does not affect the derivation of the subclass, but the behavior of the sublclass constructor defined in that line. – taz Sep 28 '12 at 03:22
  • @taz moreover, you can define private constructor in class signature: `class Foo private (bar: String) {...}` – om-nom-nom Sep 28 '12 at 09:50