Reputation: 16941
Is it possible to extend multiple classes in Scala.
For example if I have ClassA and ClassB then can ClassC extend ClassA and ClassB (like in C++).
Upvotes: 48
Views: 50078
Reputation: 2311
No, ClassC
just can extend one of those, but you can mixin multiple traits.
Upvotes: 32
Reputation: 7317
You can't extend multiple classes, but you can extend several traits. Unlike Java interfaces, traits can also include implementation (method definitions, data members, etc.). There is still a difference in that you can't instantiate a trait directly (similar to abstract classes in a way).
trait T1
trait T2
trait T3
class C extends T1 with T2 with T3
Upvotes: 50