In following code, why does method A1
of traits C
and D
are called even though class B has defined A1
?
scala> trait A {
| def A1 = A2
| def A2 //A2 is abstract and need implementation
| }
defined trait A
scala> class B extends A {
| def A2 = println("B") //implemented A2 in B
| }
defined class B
scala> val b1 = new B
b1: B = B@163e8949
this works fine.
scala> b1.A1
B
scala> b1.A2
B
now I mix traits. C still has A2 abstract
scala> trait C extends A {
| abstract override def A1 = {super.A1; C}
| def C = println("C")
| }
defined trait C
D still has A2 abstract strong text
scala> trait D extends A {
| abstract override def A1 = {super.A1; D}
| def D = println("D")
| }
defined trait D
Why C and D are printed when I cam calling A1 of B. Shouldn't B's A1 only call B's A2 which is implemented to print B?
scala> val b2 = new B with C with D
b2: B with C with D = $anon$1@701d2b59
scala> b2.A1
B
C
D
scala> b2.A2
B
scala> val b3 = new B with D with C
b3: B with D with C = $anon$1@270f28cf
scala> b3.A1
B
D
C