tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
19
Task/Polymorphic-copy/D/polymorphic-copy-1.d
Normal file
19
Task/Polymorphic-copy/D/polymorphic-copy-1.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue