mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
28 lines
372 B
Scala
28 lines
372 B
Scala
use ["std"]
|
|
|
|
class Point {
|
|
def Point(x = 0, y = 0) {
|
|
this.x = x
|
|
this.y = y
|
|
}
|
|
|
|
def moveBy(p) {
|
|
this.move(p.x, p.y)
|
|
}
|
|
|
|
def move(dx, dy) {
|
|
this.x += dx
|
|
this.y += dy
|
|
}
|
|
|
|
def toString() = "(" + this.x + ", " + this.y + ")"
|
|
}
|
|
|
|
p = new Point(20, 30)
|
|
p.move(10, -5)
|
|
println p.toString()
|
|
|
|
p2 = new Point(1, 1)
|
|
p2.moveBy(p)
|
|
println p2.toString()
|