How "this" keyword is using and working in Scala Auxiliary Constructor?

Viewed 1615

I have started learning Scala just now, help me to understand that how the age is printing where student class has two parameters

class Student(id: Int, name: String) {
  var age: Int = 0
  def showDetails() {
    println(id + " " + name + " " + age)
  }
  def this(id: Int, name: String, age: Int) {
    this(id, name)
    this.age = age
  }
}

object hi {
  def main(args: Array[String]) {
    var s = new Student(101, "Sun", 20);
    s.showDetails()
  }
}
2 Answers
Related