How to resolve the algorithm Polymorphism step by step in the Objeck programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Polymorphism step by step in the Objeck programming language
Table of Contents
Problem Statement
Create two classes Point(x,y) and Circle(x,y,r) with a polymorphic function print, accessors for (x,y,r), copy constructor, assignment and destructor and every possible default constructors
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Polymorphism step by step in the Objeck programming language
Source code in the objeck programming language
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();
}
}
}
You may also check:How to resolve the algorithm Peripheral drift illusion step by step in the Delphi programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Prime decomposition step by step in the V programming language
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the Scala programming language
You may also check:How to resolve the algorithm Read entire file step by step in the GAP programming language