As shown in below code parameters in primary constructor are defined with default values and val
it means values of those parameters should not change.
But still why the values changing while initializing the constructor
//Why values of Aname and Cname is getting overwritten
class GFG(val Aname: String = "Ank", val Cname: String = "Constructors") {
def display() = {
println("Author name: " + Aname)
println("Chapter name: " + Cname)
}
}
//object main
object Main {
def main(args: Array[String]) = {
var obj = new GFG("a", "b")
obj.display()
}
}