REVISION DOC BY RABSON Flashcards

1
Q

26.What is Null safety and how do we test for it?

A

Kotlin avoids null pointer exceptions by requiring nullable types to be explicitly declared with ?. Test for null using
?.
?:
!!.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

25.Demonstrate how you implement an array, and a list, how do they differ.

A

Array: val arr = arrayOf(1, 2, 3)
List: val list = listOf(1, 2, 3)

Arrays have a fixed size, lists can be mutable (mutableListOf()).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. If/Else Statements:
A

Used to execute code based on a condition.

if (x > 10) {
println(“Greater than 10”)
} else {
println(“Less than or equal to 10”)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

23.When Statements

A

Used as a replacement for switch-case, checking multiple conditions.

when (x) {
1 -> println(“One”)
2 -> println(“Two”)
else -> println(“Other”)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

23.While Loops:

A

Repeats code while a condition is true.

var i = 0
while (i < 5) {
println(i) // Prints 0 to 4
i++
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

23.For Loops:

A

Used to iterate over collections or ranges.

for (i in 1..5) {
println(i) // Prints 1 to 5
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Demonstrate how to use when, range, for loop, while loop, repeat loop, demonstrate with examples.
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly