title: Linearization order in Scala
body: <p>I have difficulties in understanding the linearization order in Scala when working with traits:</p>
  
  <pre><code>class A {
    def foo() = "A"
  }
  
  trait B extends A {
    override def foo() = "B" + super.foo()
  }
  
  trait C extends B {
    override def foo() = "C" + super.foo()
  }
  
  trait D extends A {
    override def foo() = "D" + super.foo()
  }
  
  object LinearizationPlayground {
      def main(args: Array[String]) {
  
        var d = new A with D with C with B;
        println(d.foo) // CBDA????
    }    
  }
  </code></pre>
  
  <p>It prints <code>CBDA</code> but I can't figure out why. How is the order of the traits determined?</p>
  
  <p>Thx</p>