Examveda

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
}

A. Classes are initialized in the same order they are in the file, therefore, Aircraft should appear after Airplane

B. The code needs to pass the parameter to the base class's primary constructor. Since it does not, it receives a null

C. Abstract function always returns null

D. A superclass is initialized before its subclass. Therefore, name has not been set before it is rendered

Answer: Option C


This Question Belongs to Computer Science >> Kotlin Program

Join The Discussion

Related Questions on Kotlin Program

What is Kotlin?

A. A new version of Java.

B. A JavaScript framework.

C. A statically-typed programming language for the JVM, Android, and browser.

D. A database management system.