Hey there, default values are easy to use with functions,… I tried using them with Classes instead through inheritance and its not working… Is it a feature that only works for functions?
packagesomething.objectorientedprograming
open class Shape(open val name:String)
{
open fun area() = 0.0
}
class Circle(override val name : String = "Big circle" , val radius : Double) : Shape(name)
{
override fun area(): Double = Math.PI * Math.pow(radius, 2.0)
}
fun main(args: Array<String>) {
// Use inheritance...
val smallCircle = Circle(7.0) // TRIED TO USE DEFALUT VALUE HERE...
// properties from object
println(smallCircle.name)
println(smallCircle.radius)
// get area
println("The area is: ${smallCircle.area()}")
}
Is there a specific reason this feature does not work with classes?