Kotlin - Basics and JVM RuntimeYou want to create a Kotlin data class to hold user info with automatic equals, hashCode, and toString. Which code is correct?Arecord User(val name: String, val age: Int)Bdata class User(val name: String, val age: Int)Cclass User(val name: String, val age: Int)Dstruct User(val name: String, val age: Int)Check Answer
Step-by-Step SolutionSolution:Step 1: Identify Kotlin's data class syntaxdata class keyword creates a class with auto-generated equals, hashCode, and toString.Step 2: Check other options for correctnessclass lacks auto-generated methods; record and struct are not Kotlin keywords.Final Answer:data class User(val name: String, val age: Int) -> Option BQuick Check:Data class syntax = C [OK]Quick Trick: Use 'data class' for auto-generated methods in Kotlin [OK]Common Mistakes:MISTAKESUsing plain class instead of data classConfusing Kotlin with Java recordsUsing non-existent keywords like struct
Master "Basics and JVM Runtime" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Map creation (mapOf, mutableMapOf) - Quiz 12easy Collections Fundamentals - Mutable vs immutable interfaces - Quiz 3easy Collections Fundamentals - Collection size and emptiness checks - Quiz 11easy Functions - Nothing return type for unreachable - Quiz 4medium Null Safety - Why null safety is Kotlin's defining feature - Quiz 14medium Operators and Expressions - Arithmetic operators - Quiz 2easy Operators and Expressions - Operator overloading concept - Quiz 5medium Operators and Expressions - Why operators are functions in Kotlin - Quiz 2easy Variables and Type System - Constant values with const val - Quiz 13medium Variables and Type System - Explicit type declaration - Quiz 2easy