Kotlin - Null SafetyHow do you declare a variable of type String that can hold null values in Kotlin?Aval name: String!Bval name: StringCval name: Nullable<String>Dval name: String?Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Kotlin's nullable syntaxKotlin uses a question mark (?) after the type to indicate nullability.Step 2: Identify correct declarationOnly val name: String? allows the variable to hold null values.Final Answer:val name: String? -> Option DQuick Check:Nullable types require '?' [OK]Quick Trick: Use '?' after type for nullable variables [OK]Common Mistakes:MISTAKESUsing non-nullable type without '?'Using 'Nullable' which is invalidUsing 'String!' which is not Kotlin syntax
Master "Null Safety" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Mutable vs immutable interfaces - Quiz 3easy Collections Fundamentals - Array creation and usage - Quiz 2easy Functions - Local functions (nested functions) - Quiz 3easy Functions - Vararg parameters - Quiz 9hard Kotlin Basics and JVM Runtime - Print and println output - Quiz 13medium Kotlin Basics and JVM Runtime - Main function as entry point - Quiz 5medium Null Safety - Safe casts with as? - Quiz 10hard Null Safety - Null safety in collections - Quiz 4medium Null Safety - Nullable types with ? suffix - Quiz 5medium Variables and Type System - String templates and interpolation - Quiz 7medium