menu

Kotlin Variables and Data Types

Kotlin Variables and Data Types - Important Points


6. Which of the following data types in Kotlin is used to represent characters?

A. Char

B. String

C. Int

D. Float

Discuss Work Space

Answer: option a

Explanation:

In Kotlin, the Char data type is used to represent characters.

7.

What is the output of the following Kotlin code?

fun main() {
val name = "John"
println("Hello, $name!")
}

A. Hello, $name!

B. Hello, John!

C. Hello, {name}!

D. Hello, {John}!

Discuss Work Space

Answer: option b

Explanation:

The $name expression in the string template is replaced with the value of the variable "name". So, the output of the code snippet is "Hello, John!".

8. Which of the following is a valid Kotlin variable name?

A. myVariableName

B. MyVariableName

C. my-variable-name

D. 1myvariablename

Discuss Work Space

Answer: option a

Explanation:

In Kotlin, variable names should start with a letter or an underscore. Option A is a valid variable name that follows this rule.

9.

What is the output of the following Kotlin code?

fun main() {
var num = 5
num = num + 2
println(num)
}

A. 5

B. 7

C. num + 2

D. 5 + 2

Discuss Work Space

Answer: option b

Explanation:

The value of the variable "num" is updated to 7 using the assignment operator "+=". So, the output of the code snippet is 7.

10. Which of the following data types in Kotlin is used to represent true or false values?

A. Char

B. String

C. Int

D. Boolean

Discuss Work Space

Answer: option d

Explanation:

In Kotlin, the Boolean data type is used to represent true or false values.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now