Sunday, April 21, 2013

Traits

For a class that wants to inherit from more than one superclass, it can use inherit from traits. Traits are like abstract classes defined as:
trait name {}
Classes and objects can only inherit from one superclass, but many traits. For example,
class Square extends Shapes with Planar with Movable ...
Traits are like interfaces in Java, but are more powerful since they can contain fields and concrete methods. However, they cannot have valued parameters.
 

No comments:

Post a Comment