Kotlin Variables and Data Types
Kotlin Variables and Data Types - Important Points
1. | Which of the following is a valid Kotlin variable declaration? |
---|
A. var name = "John"
B. var 1name = "John"
C. var name = 1
D. var name: String = "John"
View Answer Discuss Work SpaceAnswer: option a
Explanation:
In Kotlin, variable names cannot start with a number. Option A is a valid variable declaration that initializes a variable named "name" with the value "John".
2. | What is the default value of an uninitialized Kotlin variable of type Int? |
---|
A. null
B. 0
C. 0
D. 0
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The default value of an uninitialized Kotlin variable of type Int is 0.
3. | Which of the following data types in Kotlin is used to represent floating-point numbers? |
---|
A. Int
B. Long
C. Float
D. Double
View Answer Discuss Work SpaceAnswer: option d
Explanation:
In Kotlin, the Double data type is used to represent floating-point numbers.
4. | Which of the following is a valid way to declare a constant variable in Kotlin? |
---|
A. const val name = "John"
B. var name = "John"
C. val name = "John"
D. final val name = "John"
View Answer Discuss Work SpaceAnswer: option c
Explanation:
In Kotlin, constant variables can be declared using the "val" keyworOption C is a valid declaration of a constant variable named "name" with the value "John".
5. | What is the maximum value that can be stored in a Kotlin variable of type Short? |
---|
A. 255
B. 32767
C. 2147483647
D. 9.22337203685477e18
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The maximum value that can be stored in a Kotlin variable of type Short is 32767.