RosettaCodeData/Task/Polymorphic-copy/D/polymorphic-copy-1.d
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

19 lines
375 B
D

class T {
override string toString() { return "I'm the instance of T"; }
T duplicate() { return new T; }
}
class S : T {
override string toString() { return "I'm the instance of S"; }
override T duplicate() { return new S; }
}
void main () {
import std.stdio;
T orig = new S;
T copy = orig.duplicate();
writeln(orig);
writeln(copy);
}