81.
You have written a snippet of code to display the results of the roll of a six-sided die. When the die displays from 3 to 6 inclusive, you want to display a special message. Using a Kotlin range, what code should you add?
when (die) {
  1 -> println("die is 1")
  2 -> println("die is 2")
  ___ -> printlin("die is between 3 and 6")
  else -> printlin("dies is unknown")
}

82.
Why does not this code snippet compile?
class Cat (name: String) {
  fun greet() { println("Hello ${this.name}") }
}

fun main() {
  val thunderCat = Cat("ThunderCat")
  thunderCat.greet()
}

83.
What is the output of the following code?
fun main() {
    val num = 15
    when (num) {
        10 -> println("Ten")
        15 -> println("Fifteen")
        20 -> println("Twenty")
        else -> println("Other")
    }
}

85.
Why doesn't this code compile?
val addend = 1
infix fun Int.add(added: Int=1) = this + addend
fun main(){
  val msg = "Hello"
  println( msg shouldMatch "Hello")    
  println( 10 multiply 5 + 2)
  println( 10 add 5)
}

86.
You have started a long-running coroutine whose job you have assigned to a variable named task. If the need arose, how could you abort the coroutine?
val task = launch {
  // long running job
}

87.
In order to subclass the Person class, what is one thing you must do?
abstract class Person(val name: String) {
  abstract fun displayJob(description: String)
}

88.
What is to in the example below:
val test = 33 to 42

89.
You have a function simple() that is called frequently in your code. You place the inline prefix on the function. What effect does it have on the code?
inline fun simple(x: Int): Int{
  return x * x
}

fun main() {
  for(count in 1..1000) {
    simple(count)
  }
}

90.
This code snippet compiles without error, but never prints the results when executed. What could be wrong?
Val result = generateSequence(1) { it + 1 }.toList(); Println(result)

Read More Section(Kotlin Program)

Each Section contains maximum 100 MCQs question on Kotlin Program. To get more questions visit other sections.