Polymorphic copy: Difference between revisions
m
→{{header|Sidef}}: improved the demonstration
m (Added the Sidef language) |
m (→{{header|Sidef}}: improved the demonstration) |
||
Line 1,617:
=={{header|Sidef}}==
''Sys.copy()'' makes a deep-copy of any object and returns it to the caller.
<lang ruby>class T(value) {
method
}
}
class S(value) < T {
method
}
}
var obj1 = T
var obj2 = S
var obj3 = Sys.copy(obj2); # make a copy to obj2
obj1.value = "foo"; # change the value of obj1
obj2.value = "bar"; # change the value of obj2
obj1.display; # prints "foo"
obj2.display; # prints "bar"
obj3.display; # prints "S"</lang>
=={{header|Slate}}==
|