RosettaCodeData/Task/Polymorphism/Wollok/polymorphism.wollok

44 lines
717 B
Plaintext

class Point {
var x
var y
new(ax, ay) {
this.x = ax
this.y = ay
}
new(point) {
this(point.x, point.y)
}
method getX() { return x }
method setX(newX) { x = newX }
method getY() { return y }
method setY(newY) { y = newY }
method print() {
console.println("Point")
}
}
class Circle extends Point {
var r
new() { this(0,0,0) }
new(point, aR) { super(point) ; r = aR }
new(aX, aY, aR) { super(aX, aY); r = aR }
method getR() { return r }
method setR(newR) { r = newR }
method print() {
console.println("Circle")
}
}
program polymorphism {
val p = new Point()
val c = new Circle()
p.print()
c.print()
}