Skip to content

Instantly share code, notes, and snippets.

@parthdesai1208
Last active March 28, 2024 07:01
Show Gist options
  • Save parthdesai1208/24b782d9fc1dc744e8b2de3f9126deb8 to your computer and use it in GitHub Desktop.
Save parthdesai1208/24b782d9fc1dc744e8b2de3f9126deb8 to your computer and use it in GitHub Desktop.
Kotlin Constructor
open class A{
init {
println("init A")
}
constructor(){
println("primary constructor of A")
}
constructor(x:Int) : this() {
println("Secondary constructor of A: $x")
}
}
class B : A{
init {
println("init B")
}
constructor(){
println("Primary constructor of B")
}
constructor(x : Int) {
println("Secondary constructor of B: $x")
}
}
fun main() {
val a = B(300)
}
output:-
init A
primary constructor of A
init B
Secondary constructor of B: 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment