Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
object TraitParameters extends App {
trait Order(quantity: Int) {
val printQuantity: String = s"This order has a quantity of $quantity"
}
class Buy(q: Int) extends Order(q)
class Sell(q: Int) extends Order(q)
object Trade {
def buy(q: Int): Buy = new Buy(q)
def sell(q: Int): Sell = new Sell(q)
}
val buy1 = Trade.buy(100)
println(buy1.printQuantity)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment