What is the correct way to declare a variable of type integer in Kotlin?
A)var i: int = 42
B)var i: Int = 42
C)let i = 42
D)int i = 42
B)var i: Int = 42
Who designed Kotlin?
Jetbrains
What is the type of arr in the below code?
val arr = arrayOf(1, 2, 3)
A)int[]
B)IntArray
C)Int[]
D)Array<Int>
D)Array<Int>
How to create a static method in kotlin?
class Foo {
companion object{
fun bar(): String = "Kotlin"
}
}
Which of the following is not a modifier keyword in kotlin?
A)noinline
B)data
C)static
D)inline
E)None of the above options
C)static
Difference between == and === in Kotlin?
== is to check structural equality, which uses the equals implementation
=== is to check referential equality, to check if both fields point to the same object reference
What is the equivalent of the following Java expression in Kotlin?
int x = a ? b : c
A)val x = a ? b : c
B)val x = if(a) b else c
C)val x = if(a) b : c
D)val x = a ?: b, c
B)val x = if(a) b else c
How does the Elvis operator work in below two scenarios?
a)
val x: String? = "foo"
val y: String = x ?: "bar"
b)
val a: String? = null
val b: String = a ?: "bar"
val x: String? = "foo"
val y: String = x ?: "bar" // "foo", because x was non-null
val a: String? = null
val b: String = a ?: "bar" // "bar", because a was null
What does the below code print?
val listA = mutableListOf(1,2,3)
val listB = listA.add(4)
println(listB)
A)Unit
B)[1, 2, 3, 4]
C)Compilation error
D)true
D)true
What does Nothing below mean?
fun fail(message: String): Nothing {
//some code
}
fun fail(message: String): Nothing {
throw IllegalArgumentException(message)
}
The type of the throw expression is the special type Nothing. The type has no values and is used to mark code locations that can never be reached. In your own code, you can use Nothing to mark a function that never returns.