https://kotlinlang.org logo
Title
p

Pau

10/06/2020, 11:51 AM
Anyone can help me to link this test: A
class Rectangle {
    val width: Int
    val length: Int

    constructor(_width: Int, _length: Int) {
        width = _width
        length = _length
    }
}

val rectangle = Rectangle()
B
class Rectangle {
    val width: Int
    val length: Int

    constructor(width: Int, length: Int) {
        width = width
        length = length
    }
}
C
class Rectangle {
    val width: Int
    val length: Int
    
    constructor(_width: Int, _length: Int) {
        width = _width
        length = _length
    }

    constructor(_sizeA: Int, _sizeB: Int) {
        width = _sizeA
        length = _sizeB
    }
}
D
class Rectangle {
    val width: Int
    val length: Int

    constructor(width: Int, length: Int) {
        
    }
}
E
class Rectangle {
    val width: Int = 1
    val length: Int = 1

    constructor(width: Int, length: Int) {
        this.width = width
        this.length = length
    }
}
F
class Rectangle() {
    var width: Int = 1
    var length: Int = 1

    constructor(width: Int, length: Int) {
        this.width = width
        this.length = length
    }
}
I am a bit confused 🧐 1. Signature uniqueness violation 2. Primary constructor call is absent 3. Reassigning previously 4. Uninitialized properties 5. No values passed for constructor pararmeters 6. Reassigning val because of name collision
v

Vampire

10/06/2020, 12:20 PM
Why don't you just try it, for example on play.kotl.in? Should be A - 5 B - 6 C - 1 D - 4 E - 3 F - 2
t

tseisel

10/06/2020, 4:36 PM
I know that's a technical test to grasp the syntax, but I don't understand the point of this question ... every Kotlin developer would have written
class Rectangle(val width: Int, val length: Int)
v

Vampire

10/06/2020, 4:41 PM
Probably to gather insight. Test questions are seldomly related to real code.
p

Pau

10/06/2020, 4:43 PM
@Vampire thanks for the answer, I didnt know I could run this code in play.kotl. Again, thanks!
v

Vampire

10/06/2020, 4:51 PM
But better understand why the pairs are like they are 😉
p

Pau

10/06/2020, 4:52 PM
Definitely, I am into it.
👌 1