Last active
March 28, 2024 07:01
-
-
Save parthdesai1208/24b782d9fc1dc744e8b2de3f9126deb8 to your computer and use it in GitHub Desktop.
Kotlin Constructor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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