How to "override" work when inherited traits are combined?

I am experimenting with multiple inheritance in Scala. I understand that there is permission from right to left, but I do not understand the role of the keyword override. Consider the following snippet:

trait A           { def          method                }
class B extends A { def          method = println("B") }
trait C extends A { override def method = println("C") }
trait E           {                                    }
class D extends B with C with E

It compiles fine, but if I remove overridefrom the right-most attribute that defines method, it will be broken. Why is this? Is the method overridden even without a keyword?

+4
source share
1 answer

( ) , override. , - . :

trait X { def foo = "foo" }
class Y { def foo = "bar" }
class Z extends Y with X  // Does not compile

, , : , ( ).

, , , :

trait L { def m: String }
trait M extends L { def m = "m" }
trait N extends L { def m = "M" }
trait O extends L { override def m = "?" }
class P extends M with N with O  // All good
class Q extends M with N { override def m = "." } // Also good

, " ", , .

class R extends O with N

, O m ( , ), N , .

, P , m N m, O , . , .

+3

All Articles