Created
May 15, 2016 00:51
-
-
Save ryandavidhartman/4f671393236e9baf1593c7333b4c4b2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait A { | |
def foo(text: String) = printf("a says:" + text) | |
} | |
trait B extends A { | |
override def foo(text: String) = printf("b says:" + text) | |
} | |
trait C extends A { | |
override def foo(text: String) = printf("c says:" + text) | |
} | |
class D extends B with C | |
object main { | |
def main(args: Array[String]) { | |
val test = new D | |
test.foo("hi") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scala allows multiple instantiation of traits, which allows for multiple inheritance by adding a distinction between the class hierarchy and the trait hierarchy. A class can only inherit from a single class, but can mix-in as many traits as desired. Scala resolves method names using a right-first depth-first search of extended 'traits', before eliminating all but the last occurrence of each module in the resulting list. So, the resolution order is: [D, C, A, B, A], which reduces down to [D, C, B, A].
Tcl allows multiple parent classes; the order of specification in the class declaration affects the name resolution for members using the C3 linearization algorithm.[10]