- class Point private (private var x:Int, private var y:Int):
- def translate (xDisp:Int, yDisp:Int) : Unit =
- x = x + xDisp
- y = y + yDisp
- object Point:
- def apply (x:Int, y:Int) : Point =
- if 0 <= x && x <= 10 && 0 <= y && y <= 10 then
- new Point (x, y)
- else
- throw IllegalArgumentException (s"Both x and y must be in range [0,10], but x=$x and y=$y.")
- val p = Point.apply (1, 100)
- val q = Point.apply (1, 10)
- val r = Point (1, 10)
- val s = new Point (1, 100)