Inheritance/Single: Difference between revisions

Content deleted Content added
Add NetRexx implementation
Line 789:
// ...
}</lang>
 
=={{header|NetRexx}}==
Class names cosmetically augmented slightly to prevent namespace pollution.
 
For brevity, all classes are defined within the same source file. Normally classes exist as separate source units.
<lang NetRexx>/* NetRexx */
options replace format comments java crossref symbols binary
 
class RInheritSingle public
method main(args = String[]) public static
animals = [ -
RInheritSingle_Animal(), -
RInheritSingle_Cat(), -
RInheritSingle_Dog(), -
RInheritSingle_Lab(), -
RInheritSingle_Collie() -
]
 
say 'Object ID'.left(12) 'Class type'.left(24) 'Superclass type'
say '.'.left(12, '.') '.'.left(24, '.') '.'.left(24, '.')
loop animal over animals
parse animal.whatAmI() oid ct st
say oid.left(12) ct.left(24) st
end animal
return
 
class RInheritSingle_Animal private
properties indirect
whatThatIs = String
whatThisIs = String
method RInheritSingle_Animal() public
-- Animal specific set-up
setWhatThatIs(this.getClass().getSuperclass().getSimpleName())
setWhatThisIs(this.getClass().getSimpleName())
return
method hashToString() public
return '@'(Rexx this.hashCode()).d2x().right(8, 0)
method whatAmI() public
iAmText = hashToString() getWhatThisIs() getWhatThatIs()
return iAmText
 
class RInheritSingle_Cat private extends RInheritSingle_Animal
method RInheritSingle_Cat() public
-- Do Cat specific set-up
return
 
class RInheritSingle_Dog private extends RInheritSingle_Animal
method RInheritSingle_Dog() public
-- Do Dog specific set-up
return
 
class RInheritSingle_Lab private extends RInheritSingle_Dog
method RInheritSingle_Lab() public
-- Do Lab specific set-up
return
 
class RInheritSingle_Collie private extends RInheritSingle_Dog
method RInheritSingle_Collie() public
-- Do Collie specific set-up
return
</lang>
{{out}}
<pre>
Object ID Class type Superclass type
............ ........................ ........................
@3F81D405 RInheritSingle_Animal Object
@51430296 RInheritSingle_Cat RInheritSingle_Animal
@065EEF88 RInheritSingle_Dog RInheritSingle_Animal
@42BFCCFC RInheritSingle_Lab RInheritSingle_Dog
@3E2AD6A0 RInheritSingle_Collie RInheritSingle_Dog
</pre>
 
=={{header|Objective-C}}==