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"

Computer Science

ScanSolve AI Answer

Here are the correct Kotlin variable declarations:

  • kotlin var age: Int? = 30 This is a valid declaration. var indicates a mutable variable. Int? declares a nullable integer type, meaning it can hold an Int value or null. Assigning 30 (an Int) to it is perfectly fine.

  • kotlin val name: String = "Kotlin" This is a valid declaration. val indicates an immutable (read-only) variable. String declares a string type. Assigning the string literal "Kotlin" to it is correct.

The other options are incorrect:

  • kotlin var score: Double = 0.0 score = null The first line var score: Double = 0.0 is valid. However, the second line score = null is invalid because score is declared as Double (a non-nullable type), and you cannot assign null to a non-nullable type. To allow null, it should be declared as Double?.

  • kotlin val isActive: Boolean = "true" This is invalid because "true" is a String literal, but the variable isActive is declared as Boolean. A Boolean variable must be assigned true or false (without quotes).

The final answers are kotlin var age: Int? = 30\boxed{\text{kotlin var age: Int? = 30}} and kotlin val name: String = "Kotlin"\boxed{\text{kotlin val name: String = "Kotlin"}}

Was this helpful?

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question