Jump to content

Polymorphism: Difference between revisions

PascalABC.NET
(Added FreeBASIC)
(PascalABC.NET)
 
Line 3,440:
=={{header|Pascal}}==
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}}==
246

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.