Difference between Abstract Class and Trait

Red Hyena picture Red Hyena · Jan 5, 2010 · Viewed 55.8k times · Source

Possible Duplicate:
Scala traits vs abstract classes

What is the conceptual difference between abstract classes and traits?

Answer

Hans-Peter Störr picture Hans-Peter Störr · Jan 5, 2010

A class can only extend one superclass, and thus, only one abstract class. If you want to compose several classes the Scala way is to use mixin class composition: you combine an (optional) superclass, your own member definitions and one or more traits. A trait is restricted in comparison to classes in that it cannot have constructor parameters (compare the scala reference manual).

The restrictions of traits in comparison to classes are introduced to avoid typical problems with multiple inheritance. There are more or less complicated rules with respect to the inheritance hierarchy; it might be best to avoid a hierarchy where this actually matters. ;-) As far as I understand, it can only matter if you inherit two methods with the same signature / two variables with the same name from two different traits.