tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
82
Task/Polymorphism/Objeck/polymorphism.objeck
Normal file
82
Task/Polymorphism/Objeck/polymorphism.objeck
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
bundle Default {
|
||||
class Point {
|
||||
@x : Int;
|
||||
@y : Int;
|
||||
|
||||
New() {
|
||||
@x := 0;
|
||||
@y := 0;
|
||||
}
|
||||
|
||||
New(x : Int, y : Int) {
|
||||
@x := x;
|
||||
@y := y;
|
||||
}
|
||||
|
||||
New(p : Point) {
|
||||
@x := p->GetX();
|
||||
@y := p->GetY();
|
||||
}
|
||||
|
||||
method : public : GetX() ~ Int {
|
||||
return @x;
|
||||
}
|
||||
|
||||
method : public : GetY() ~ Int {
|
||||
return @y;
|
||||
}
|
||||
|
||||
method : public : SetX(x : Int) ~ Nil {
|
||||
@x := x;
|
||||
}
|
||||
|
||||
method : public : SetY(y : Int) ~ Nil {
|
||||
@y := y;
|
||||
}
|
||||
|
||||
method : public : Print() ~ Nil {
|
||||
"Point"->PrintLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Circle from Point {
|
||||
@r : Int;
|
||||
|
||||
New() {
|
||||
Parent();
|
||||
@r := 0;
|
||||
}
|
||||
|
||||
New(p : Point) {
|
||||
Parent(p);
|
||||
@r := 0;
|
||||
}
|
||||
|
||||
New(c : Circle) {
|
||||
Parent(c->GetX(), c->GetY());
|
||||
@r := c->GetR();
|
||||
}
|
||||
|
||||
method : public : GetR() ~ Int {
|
||||
return @r;
|
||||
}
|
||||
|
||||
method : public : SetR(r : Int) ~ Nil {
|
||||
@r := r;
|
||||
}
|
||||
|
||||
method : public : Print() ~ Nil {
|
||||
"Circle"->PrintLine();
|
||||
}
|
||||
}
|
||||
|
||||
class Poly {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
p := Point->New();
|
||||
c := Circle->New();
|
||||
p->Print();
|
||||
c->Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue