author | Chengsong |
Fri, 26 May 2023 08:09:30 +0100 | |
changeset 646 | 56057198e4f5 |
parent 44 | a751aa1ee4f7 |
permissions | -rw-r--r-- |
44 | 1 |
package Main |
2 |
||
3 |
class Point(xc: Int, yc: Int) { |
|
4 |
var x: Int = xc |
|
5 |
var y: Int = yc |
|
6 |
def move(dx: Int, dy: Int) { |
|
7 |
x = x + dx |
|
8 |
y = y + dy |
|
9 |
} |
|
10 |
override def toString(): String = "(" + x + ", " + y + ")"; |
|
11 |
} |
|
12 |
||
13 |
object Classes{ |
|
14 |
def main(args: Array[String]){ |
|
15 |
val pt = new Point(1,2) |
|
16 |
println(pt) |
|
17 |
pt.move(10,10) |
|
18 |
println(pt) |
|
19 |
} |
|
20 |
} |