Differences between trait and abstract class

  1. A class can inherit from multiple traits but only one abstract class.
  2. Abstract classes can have constructor parameters as well as type parameters. Traits can have only type parameters. For example, you can’t say trait t(i: Int) {}; the i parameter is illegal.
  3. Abstract classes are fully interoperable with Java. You can call them from Java code without any wrappers. Traits are fully interoperable only if they do not contain any implementation code.
trait Car {
  val brand: String
}

trait Shiny{
  val shineRefraction: Int 
}

trait Miles{
  val miles: Int
}

class BMW extends Car with Shiny with Miles{
  val brand = "BMW"
  val shineRefraction = 12
  val miles = 500
}