Inheritance/Single: Difference between revisions
Content deleted Content added
m {{out}} |
|||
Line 1,383:
buddy.kill()
print "Felix has",felix.lives, "lives, ","Buddy is %salive!"%("" if buddy.alive else "not ")</lang>
{{out}}
Felix has 6 lives, Buddy is not alive!
</pre>
Line 1,448 ⟶ 1,449:
print ["Lab says:" Lab/says]</lang>
{{out}}
<pre>Cat has 4 legs.
Lab says: Woof!</pre>
Line 1,478:
end</lang>
{{out}}
<pre>new subclass of Animal: Dog
new subclass of Dog: Lab
Line 1,486:
=={{header|Scala}}==
Scala has both classes and traits. Classes can only be singly inherited, but both
can inherit a trait multiple times.
This inheritance can be declared at the point
of instantiation as well, precluding the need to declare a trait or class for the
sole purpose of combining traits.
For the simple inheritance chain of this task,
any (or all) of the <code>class</code> keywords below can be replaced with <code>trait</code>
Line 1,617 ⟶ 1,619:
@(end)</lang>
{{out}} Test:
<pre>$ txr dog-cat.txr
arg="x"</pre>
Line 1,674 ⟶ 1,675:
L(Class(Collie),Class(Dog),Class(Animal))
</pre>
|