Quantcast
Channel: Kotlin: 'val' on secondary constructor parameter is not allowed - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by Mahdi A for Kotlin: 'val' on secondary constructor parameter is not allowed

$
0
0

You can define the variable as val or var in the class you inherit from

   open class Human(val name: String) constructor(name: String) {            open fun showInfo()        {            println("Show Info")        }        }class Person:Human {constructor(name: String) : super(name)    private var surname: String = "Unknown"  override fun showInfo() {        println("$name And surname is $surname")    }}

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>