Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
52
Task/Polymorphism/Ceylon/polymorphism.ceylon
Normal file
52
Task/Polymorphism/Ceylon/polymorphism.ceylon
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import ceylon.language {
|
||||
consolePrint = print
|
||||
}
|
||||
|
||||
shared void run() {
|
||||
|
||||
class Point {
|
||||
|
||||
shared variable Integer x;
|
||||
shared variable Integer y;
|
||||
|
||||
shared new(Integer x = 0, Integer y = 0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
shared new copy(Point p) {
|
||||
this.x = p.x;
|
||||
this.y = p.y;
|
||||
}
|
||||
|
||||
shared default void print() {
|
||||
consolePrint("[Point ``x`` ``y``]");
|
||||
}
|
||||
}
|
||||
|
||||
class Circle extends Point {
|
||||
|
||||
shared variable Integer r;
|
||||
|
||||
shared new(Integer x = 0, Integer y = 0, Integer r = 0) extends Point(x, y) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
shared new copy(Circle c) extends Point.copy(c){
|
||||
this.r = c.r;
|
||||
}
|
||||
|
||||
shared actual void print() {
|
||||
consolePrint("[Circle ``x`` ``y`` ``r``]");
|
||||
}
|
||||
}
|
||||
|
||||
value shapes = [
|
||||
Point(), Point(1), Point(1, 2), Point {y = 3;}, Point.copy(Point(4, 5)),
|
||||
Circle(), Circle(1), Circle(2, 3), Circle(4, 5, 6), Circle {y = 7; r = 8;}, Circle.copy(Circle(9, 10, 11))
|
||||
];
|
||||
|
||||
for(shape in shapes) {
|
||||
shape.print();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue