Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created June 16, 2015 19:06
Show Gist options
  • Save khajavi/d9bb6eaf6fbb792f71be to your computer and use it in GitHub Desktop.
Save khajavi/d9bb6eaf6fbb792f71be to your computer and use it in GitHub Desktop.
Multiple Inheritance in Scala
object Simulation {
def main(args: Array[String]): Unit= {
trait A {
var distance: Int = _
def action = {
distance = distance + 5
}
}
trait B {
var driverVar: Int = _
def action = {
driverVar = driverVar + 1
}
}
class AB extends A with B {
distance = 3;
driverVar = 6;
override def action = {
super[A].action
super[B].action
}
}
var ab = new AB
ab.action
println(ab.driverVar)
println(ab.distance)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment