Super behavior with the same method in two hierarchies
Having these traits and classes:
trait A {
def print() {
println("A")
}
}
trait B extends A {
override def print() {
println("B")
super.print()
}
}
trait C extends A {
override def print() {
println("C")
super.print()
}
}
class H {
def print() {
println("H")
}
}
class X extends H with B with C {
override def print() {
println("X"); super.print()
}
}
And call print from object X:
val x = new X
x.print
The print I get is this:
X
C
B
A
Is it possible at some point to achieve a print-in H class
method starting from a print-in method X class
?
I see traits A, B and C belonging to one hierarchy, and H in another hierarchy. In both hierarchies, we have a printing method. Having class X
expanded both hierarchies, I think there must also be a way to achieve the print method from class H
. After all, it class X
is defined as "class X extends H ....".
I think I am missing something important here; I guess I don't quite understand.
Many thanks for your help.
source to share