Kotlin - Variables and Type SystemHow would you explicitly declare a nullable string variable in Kotlin and assign it a null value?Aval name: String = nullBvar name: String? = nullCvar name: String = ?nullDval name: String? = "null"Check Answer
Step-by-Step SolutionSolution:Step 1: Understand nullable type syntaxIn Kotlin, a nullable type is declared by adding a question mark after the type, e.g., String?.Step 2: Assign null to nullable variablevar name: String? = null correctly declares a mutable nullable string variable and assigns it null.Final Answer:var name: String? = null -> Option BQuick Check:Nullable type uses '?' after type [OK]Quick Trick: Add '?' after type to allow null values [OK]Common Mistakes:MISTAKESAssigning null to non-nullable typeUsing quotes around nullIncorrect nullable syntax
Master "Variables and Type System" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Set creation (setOf, mutableSetOf) - Quiz 1easy Control Flow as Expressions - When without argument - Quiz 8hard Data Types - Unit type as void equivalent - Quiz 2easy Data Types - Int, Long, Float, Double number types - Quiz 4medium Data Types - Number literal formats (underscore, hex, binary) - Quiz 6medium Functions - Infix functions for readable calls - Quiz 5medium Null Safety - Why null safety is Kotlin's defining feature - Quiz 8hard Operators and Expressions - Why operators are functions in Kotlin - Quiz 13medium Variables and Type System - Val for immutable references - Quiz 12easy Variables and Type System - Constant values with const val - Quiz 4medium