menu

Kotlin Variables and Data Types


1. What is the default value of an uninitialized Kotlin variable of type Int?

null

0

0

0


2. Which of the following data types in Kotlin is used to represent floating-point numbers?

Int

Long

Float

Double


3. Which of the following is a valid way to declare a variable in Kotlin with a constant value?

var PI: Float = 3.14f

val PI = 3.14f

const val PI = 3.14f

final val PI = 3.14f


4.

What is the output of the following Kotlin code?

fun main() {
val a = 5
val b = 2
val result = a.toDouble() / b
println(result)
}

2.5

2

2

2.5f


5. Which of the following is a valid way to declare a variable in Kotlin with a default value?

var count = 0

var count: Int

var count: Int = null

var count = null


6. Which of the following is a valid Kotlin variable declaration?

var name = "John"

var 1name = "John"

var name = 1

var name: String = "John"


7.

What is the output of the following Kotlin code?

fun main() {
val name: String? = null
println(name?.length)
}

null

0

Compilation error

Runtime error


8.

What is the output of the following Kotlin code?

fun main() {
var num = 5
num = num + 2
println(num)
}

5

7

num + 2

5 + 2


9. Which of the following is a valid way to declare a nullable variable in Kotlin?

var name: String = null

var name: String? = null

var name: Nullable = null

var name: NullableString = null


10.

What is the output of the following Kotlin code?

fun main() {
val name = "John"
println("Hello, $name!")
}

Hello, $name!

Hello, John!

Hello, {name}!

Hello, {John}!