Created
June 16, 2015 19:06
-
-
Save khajavi/d9bb6eaf6fbb792f71be to your computer and use it in GitHub Desktop.
Multiple Inheritance in Scala
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
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