We read your photo as:
Which Kotlin variable declarations are correct? Options: var age: Int? = 30, val name: String = "Kotlin", var score: Double = 0.0 score = null, val isActive: Boolean = "true"
ScanSolve AI Answer
Here are the correct Kotlin variable declarations:
-
kotlin var age: Int? = 30This is a valid declaration.varindicates a mutable variable.Int?declares a nullable integer type, meaning it can hold anIntvalue ornull. Assigning30(anInt) to it is perfectly fine. -
kotlin val name: String = "Kotlin"This is a valid declaration.valindicates an immutable (read-only) variable.Stringdeclares a string type. Assigning the string literal"Kotlin"to it is correct.
The other options are incorrect:
-
kotlin var score: Double = 0.0score = nullThe first linevar score: Double = 0.0is valid. However, the second linescore = nullis invalid becausescoreis declared asDouble(a non-nullable type), and you cannot assignnullto a non-nullable type. To allownull, it should be declared asDouble?. -
kotlin val isActive: Boolean = "true"This is invalid because"true"is aStringliteral, but the variableisActiveis declared asBoolean. ABooleanvariable must be assignedtrueorfalse(without quotes).
The final answers are and
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.