This file contains 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 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