Constructors

class Point(var x: Int = 0, var y: Int = 0)

val origin = new Point  // x and y are both set to 0
val point1 = new Point(1)
println(point1.x)  // prints 1
class Point(var x: Int = 0, var y: Int = 0)
val point2 = new Point(y=2)
println(point2.y)  // prints 2

Constructors can have optional parameters by providing a default value.

Constructors — Structure map

Clickable & Draggable!

Constructors — Related pages: