menu

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"

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: 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"

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: option b

Explanation:

The maximum value that can be stored in a Kotlin variable of type Short is 32767.


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