super class is initialized before sub class.

The constructor call of B calls the constructor of A, which calls the function f printing "x in f: 1", after A is initialized, the rest of B is initialized.

So essentially, the setting of the value is being overwritten.

(When you initialize primitives with their zero value in Kotlin, they technically just dont initialize at all)

You can observe this "overwrite" behavior by changing the signature from

var x: Int = 0 to var x: Int? = 0

Since x is no longer the primitive int , the field actually gets initialized to a value, producing the output: