0
0
Android Kotlinmobile~5 mins

Data types and type inference in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a data type in Kotlin?
A data type defines the kind of value a variable can hold, like numbers, text, or true/false values.
Click to reveal answer
beginner
What does val mean in Kotlin?
val declares a read-only variable, which means its value cannot change after it is set.
Click to reveal answer
beginner
Explain type inference in Kotlin.
Type inference means Kotlin can guess the data type of a variable from the value you assign, so you don't always need to write the type explicitly.
Click to reveal answer
beginner
What is the difference between Int and Double in Kotlin?
Int holds whole numbers without decimals, while Double holds numbers with decimals.
Click to reveal answer
beginner
How do you explicitly declare a variable type in Kotlin?
You write the variable name, then a colon, then the type. For example: val age: Int = 30.
Click to reveal answer
Which keyword declares a variable whose value cannot change in Kotlin?
Aval
Bvar
Clet
Dconst
What type will Kotlin infer for val name = "Anna"?
AString
BInt
CBoolean
DDouble
Which data type should you use for a number with decimals?
AInt
BDouble
CString
DBoolean
How do you explicitly declare a variable of type Int?
Aval number = 5 as Int
Bval number = Int(5)
Cval Int number = 5
Dval number: Int = 5
What happens if you try to change a val variable?
AIt changes successfully
BIt changes at runtime
CYou get a compile error
DIt changes only sometimes
Explain how Kotlin's type inference helps when declaring variables.
Think about how Kotlin figures out the type from the value you give.
You got /3 concepts.
    Describe the difference between val and var in Kotlin.
    Consider if the variable can be changed or not.
    You got /3 concepts.