Polymorphism: Difference between revisions
Content added Content deleted
(Added FreeBASIC) |
(PascalABC.NET) |
||
Line 3,440: | Line 3,440: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
See [[Polymorphism#Delphi | Delphi]] |
See [[Polymorphism#Delphi | Delphi]] |
||
=={{header|PascalABC.NET}}== |
|||
<syntaxhighlight lang="delphi"> |
|||
type |
|||
Point = class |
|||
public |
|||
auto property x: real; |
|||
auto property y: real; |
|||
constructor (x,y: real); |
|||
begin |
|||
Self.x := x; Self.y := y; |
|||
end; |
|||
procedure Print; virtual; |
|||
begin |
|||
PABCSystem.Print(x,y); |
|||
end; |
|||
end; |
|||
Circle = class(Point) |
|||
public |
|||
auto property r: real; |
|||
constructor (x,y,r: real); |
|||
begin |
|||
inherited Create(x,y); |
|||
Self.r := r; |
|||
end; |
|||
procedure Print; override; |
|||
begin |
|||
inherited Print; |
|||
PABCSystem.Print(r); |
|||
end; |
|||
end; |
|||
begin |
|||
var p: Point := new Point(3,5); |
|||
var c: Circle := new Circle(10,8,4); |
|||
p.Print; |
|||
Println; |
|||
c.Print; |
|||
end. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
3 5 |
|||
10 8 4 |
|||
</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |