class student1(firstName : String, lastName : String){
var id : Int = -1
val firstName = firstName
val lastName = lastName
init {
println("initialized")
}
constructor(firstName : String, lastName : String, extraParam : Int) : this(firstName, lastName){
this.id = extraParam
}
fun callme(){
print(firstName + lastName)
}
}
class student2(firstName : String, lastName : String){
val firstName = firstName
val lastName = lastName
fun callme() {
print(firstName + lastName)
}
}
fun main() {
val p1 = student1("shubham", "sharma")
println(p1.firstName)
println(p1.lastName)
println(p1.callme())
val p2 = student1("shubham", "sharma")
println(p2.firstName)
println(p2.lastName)
println(p2.callme())
}
here in both the class, the output is the same with the same parameter then why we need to use the secondary constructor? What is the main difference between these two class please let me know with one example. will be appreciated!