Skip to content

Instantly share code, notes, and snippets.

@sonumehrotra
Created December 3, 2020 02:48
Show Gist options
  • Save sonumehrotra/557aacb0b174767e1d8c1117480a5872 to your computer and use it in GitHub Desktop.
Save sonumehrotra/557aacb0b174767e1d8c1117480a5872 to your computer and use it in GitHub Desktop.
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