Inheritance/Single: Difference between revisions

Content added Content deleted
m (→‎{{header|J}}: 5*s->1)
Line 952: Line 952:
Here is how this would normally be done:
Here is how this would normally be done:


<syntaxhighlight lang="j">coclass 'Animal'</syntaxhighlight>
<syntaxhighlight lang="j">
<syntaxhighlight lang="j">coclass 'Dog'
coclass 'Animal'
coclass 'Dog'
coinsert 'Animal'</syntaxhighlight>
coinsert 'Animal'
<syntaxhighlight lang="j">coclass 'Cat'
coclass 'Cat'
coinsert 'Animal'</syntaxhighlight>
coinsert 'Animal'
<syntaxhighlight lang="j">coclass 'Lab'
coclass 'Lab'
coinsert 'Dog'</syntaxhighlight>
coinsert 'Dog'
<syntaxhighlight lang="j">coclass 'Collie'
coclass 'Collie'
coinsert 'Dog'</syntaxhighlight>
coinsert 'Dog'
</syntaxhighlight>


<code>coclass</code> specifies that following definitions will be within the named class, and <code>coinsert</code> specifies that the current class will inherit from the named classes (or object -- in J the only difference between a class and an object is its name and how you can create them -- this motivates the "co" prefix on operations which manipulate '''c'''lasses and '''o'''bjects).
<code>coclass</code> specifies that following definitions will be within the named class, and <code>coinsert</code> specifies that the current class will inherit from the named classes (or object -- in J the only difference between a class and an object is its name and how you can create them -- this motivates the "co" prefix on operations which manipulate '''c'''lasses and '''o'''bjects).