Skip to content

Instantly share code, notes, and snippets.

@lu911
Created August 3, 2013 04:35
Show Gist options
  • Save lu911/6145204 to your computer and use it in GitHub Desktop.
Save lu911/6145204 to your computer and use it in GitHub Desktop.
Assistance Constructor
object Main {
def main(args: Array[String]): Unit = {
val p1 = new Person
val p2 = new Person("Loup")
val p3 = new Person("Loup", 19)
}
class Person
{
private var name = ""
private var age = 0
def this(name: String)
{
this()
this.name = name
}
def this(name: String, age: Int)
{
this(name)
this.age = age
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment