Vidyalelo
Computer Science · Q280

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications

Engineering and GATE · Computer Science · question 280

Q280

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
Answer
D.
A superclass is initialized before its subclass. Therefore, name has not been set before it is rendered

Answer: Option C

Solution

Answer: Option C
No explanation is given for this question Let's Discuss on Board