71.
What is the difference between a and b?
var a: String? = "KotlinProgramming"
var b: String = 'KotlinProgramming"

72.
Which is true for the following simple class declaration?
class Person (val name: String)

73.
The code below compiled and executed without issue before the addition of the line declaring errorStatus. Why does this line break the code?
sealed class Status(){
  object Error : Status()
  class Success : Status()
}
fun main(){
  var successStatus = Status.Success()
  var errorStatus = Status.Error()
}

74.
The code below is expected to display the numbers from 1 to 10, but it does not. Why?
val seq = sequence { yieldAll(1..20) }
  .filter { it < 11 }
  println(seq)

75.
You have an unordered list of high scores. Which is the simple method to sort the highScores in descending order?
fun main() { val highScores = listOf(4000, 2000, 10200, 12000, 9030)}

76.
What three methods does this class have?
class Person

77.
In this code snippet, why does the compiler not allow the value of y to change?
for(y in 1..100) y+=2

78.
Both const and @JvmField create constants. What can const do that @JvmField cannot?
class Detail {
  companion object {
    const val COLOR = "Blue"
    @JvmField val SIZE = "Really Big"
  }
}

79.
You have two arrays, a and b. Which line combines a and b as a list containing the contents of both?
val a = arrayOf(1, 2, 3) val b = arrayOf(100, 200, 3000)

80.
When the Airplane class is instantiated, it displays Aircraft = null, not Aircraft = C130 why?
abstract class Aircraft {
  init { println("Aircraft = ${getName()}") }
  abstract fun getName(): String
}
class Airplane(private val name: String) : Aircraft() {
  override fun getName(): String = name
}

Read More Section(Kotlin Program)

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