Polymorphic copy: Difference between revisions
Content added Content deleted
m (→{{header|Go}}: typo) |
|||
Line 860:
print_endline (Oo.copy obj1)#name; (* prints "T" *)
print_endline (Oo.copy obj2)#name; (* prints "S" *)</lang>
=={{header|ooRexx}}==
All ooRexx objects have a copy method inherited from the object class that performs a shallow copy of the object state.
<lang ooRexx>
s = .s~new
s2 = s~copy -- makes a copy of the first
if s == s2 then say "copy didn't work!"
if s2~name == "S" then say "polymorphic copy worked"
::class t
::method name
return "T"
::class s subclass t
::method name
return "S"
</lang>
=={{header|Oz}}==
|