1

I want to inherit two classes (AbstractA and AbstractB) in some trait C:

abstract class AbstractA
trait A extends AbstractA

abstract class AbstractB
trait B extends AbstractB

trait C extends A with B

This code is not compiled:

[error] illegal inheritance; superclass AbstractA is not a subclass of the superclass AbstractB of the mixin trait B

John Mullins
  • 1,061
  • 4
  • 11
  • 38

1 Answers1

3

You can't inherit from two different classes, and as a consequence you can't even inherit from two traits inheriting from two different classes.

 AbstractA  AbstractB
    |           |
    |           |
    A           B
     \         /
      \       /
       \     /
        \   /
          C

Were this allowed, C would be subclass of both AbstractA and AbstractB, which is illegal.


What's your use case anyway?

A trait can have abstract members so you shouldn't need to inherit from an abstract class at all.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235