Jump to content

Abstract type: Difference between revisions

no edit summary
(Added COBOL section.)
No edit summary
Line 543:
(kdr 45) ; => 44</lang>
 
=={{header|Component Pascal}}==
<lang oberon2>
(* Abstract type *)
Object = POINTER TO ABSTRACT RECORD END;
(* Integer inherits Object *)
Integer = POINTER TO RECORD (Object)
i: INTEGER
END;
(* Point inherits Object *)
Point = POINTER TO RECORD (Object)
x,y: REAL
END;
</lang>
...
<lang oberon2>
(* Abstract method of Object *)
PROCEDURE (dn: Object) Show*, NEW, ABSTRACT;
(* Implementation of the abstract method Show() in class Integer *)
PROCEDURE (i: Integer) Show*;
BEGIN
StdLog.String("Integer(");StdLog.Int(i.i);StdLog.String(");");StdLog.Ln
END Show;
(* Implementation of the abstract method Show() in class Point *)
PROCEDURE (p: Point) Show*;
BEGIN
StdLog.String("Point(");StdLog.Real(p.x);StdLog.Char(',');
StdLog.Real(p.y);StdLog.String(");");StdLog.Ln
END Show;
</lang>
 
For usage see tasks Stacks.
=={{header|D}}==
<lang d>import std.stdio;
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.