Kotlin Variables and Data Types
Kotlin Variables and Data Types - Important Points
16. | Which of the following is a valid way to declare a variable in Kotlin with a default value? |
---|
A. var count = 0
B. var count: Int
C. var count: Int = null
D. var count = null
View Answer Discuss Work SpaceAnswer: option a
Explanation:
17. | Which of the following is a valid Kotlin variable declaration for a set of integers? |
---|
A. val numbers = hashSetOf(1, 2, 3)
B. val numbers: Set
C. val numbers: MutableSet
D. val numbers: Set
Answer: option d
Explanation:
18. | Which of the following is a valid way to declare a variable in Kotlin with a constant value? |
---|
A. var PI: Float = 3.14f
B. val PI = 3.14f
C. const val PI = 3.14f
D. final val PI = 3.14f
View Answer Discuss Work SpaceAnswer: option c
Explanation:
19. | Which of the following is a valid way to declare a variable in Kotlin with a lazy initialization? |
---|
A. val name by lazy = "John"
B. var name = lazy { "John" }
C. lateinit var name: String = "John"
D. val name: String? = null
View Answer Discuss Work SpaceAnswer: option a
Explanation:
20. | Which of the following is a valid way to declare a nullable variable in Kotlin? |
---|
A. var name: String = null
B. var name: String? = null
C. var name: Nullable
D. var name: NullableString = null
View Answer Discuss Work SpaceAnswer: option b
Explanation: