Child to inherit constructor

Let’s say I have this setup:

abstract class Animal(type: String?, name: String?, weight: Double?) {
    constructor() : this(null, null,null) //I want children to inherit this constructor

    abstract fun makeNoise(): String
}

class Dog(type: String?, name: String?, weight: Double?) : Animal(type, name, weight) {
    constructor() : this(null, null,null)

    override fun makeNoise(): String { return "Haf" }
}

class Human(type: String?, name: String?, weight: Double?) : Animal(type, name, weight) {
    constructor() : this(null, null,null)

    override fun makeNoise(): String { return "Hello" }

}

In other words, I want all inherited classes to have a secondary constructor that takes no arguments. As you can see, writing constructor(): this(null, null, null) for each inherited class is repetitive. Is there a more efficient and elegant way?

2 Likes