Created
December 3, 2020 02:39
-
-
Save sonumehrotra/8b2205e23b5633d367e42d5183f2f335 to your computer and use it in GitHub Desktop.
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 Order extends App { | |
trait Order { | |
val quantity: Int | |
val printQuantity: String = s"This order has a quantity of $quantity" | |
} | |
class Buy(q: Int) extends Order { | |
override val quantity: Int = q | |
} | |
class Sell(q: Int) extends Order { | |
override val quantity: Int = 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.quantity) | |
println(buy1.printQuantity) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment