Created
March 1, 2015 14:05
-
-
Save shigemk2/e8ba2448ce428b586c6d 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
// primary constructor | |
class Pizza (var crustSize: Int, var crustType: String) { | |
// one-arg auxiliary constructor | |
def this(crustSize: Int) { | |
this(crustSize, Pizza.DEFAULT_CRUST_TYPE) | |
} | |
// one-arg auxiliary constructor | |
def this(crustType: String) { | |
this(Pizza.DEFAULT_CRUST_SIZE, crustType) | |
} | |
// zero-arg auxiliary constructor | |
def this() { | |
this(Pizza.DEFAULT_CRUST_SIZE, Pizza.DEFAULT_CRUST_TYPE) | |
} | |
override def toString = s"A $crustSize inch pizza with a $crustType crust" | |
} | |
object Pizza { | |
val DEFAULT_CRUST_SIZE = 12 | |
val DEFAULT_CRUST_TYPE = "THIN" | |
} | |
val p1 = new Pizza(Pizza.DEFAULT_CRUST_SIZE, Pizza.DEFAULT_CRUST_TYPE) | |
val p2 = new Pizza(Pizza.DEFAULT_CRUST_SIZE) | |
val p3 = new Pizza(Pizza.DEFAULT_CRUST_TYPE) | |
val p4 = new Pizza | |
val p5 = new Pizza(13, "LARGE") | |
println(p1) | |
println(p2) | |
println(p3) | |
println(p4) | |
println(p5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment