Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PrelimExam-PlatTech-Ch1-4

Total questions: 70

Worksheet time: 2hrs 45mins

Name
Class
Date
1.

Kotlin is primarily designed to interoperate with which language?

a)

Python

b)

Java

c)

C++

d)

Ruby

2.

Which company developed Kotlin?

a)

Microsoft

b)

JetBrains

c)

Google

d)

Oracle

3.

Which function is used to print output in Kotlin?

a)

printOut()

b)

echo()

c)

println()

d)

display()

4.

What is the output of println(5 + 3)?

a)

8

b)

5 + 3

c)

53

d)

Error

5.

Which symbol denotes a single-line comment in Kotlin?

a)

//

b)

/*

c)

#

d)

6.

What is the correct way to write a multi-line comment in Kotlin?

a)

//

b)

#...#

c)

/.../

d)

7.

Which keyword is used to declare a mutable variable in Kotlin?

a)

let

b)

var

c)

val

d)

const

8.

What will happen if you try to change the value of a val variable?

a)

It will change successfully.

b)

It will throw an error.

c)

It will be ignored.

d)

It will create a new variable.

9.

Which of the following is not a built-in data type in Kotlin?

a)

Int

b)

String

c)

Decimal

d)

Boolean

10.

What is the range of an Int data type in Kotlin?

a)

-2^31 to 2^31-1

b)

-2^63 to 2^63-1

c)

0 to 255

d)

-128 to 127

11.

Which operator is used for string concatenation in Kotlin?

a)

&

b)

+

c)

,

d)

.

12.

What is the result of 5 == 5 in Kotlin?

a)

True

b)

False

c)

1

d)

0

13.

Which of the following correctly creates a string in Kotlin?

a)

String name = "Kotlin"

b)

var name: String = "Kotlin"

c)

name: String = "Kotlin"

d)

name = String("Kotlin")

14.

How can you embed a variable in a string in Kotlin?

a)

Using +

b)

Using $

c)

Using &

d)

Using @

15.

What will the expression true && false evaluate to?

a)

True

b)

False

c)

1

d)

0

16.

Which keyword is used to declare a Boolean variable in Kotlin?

a)

Boolean

b)

Bool

c)

Boolean

d)

bool

17.

What will the following code print: if (5 > 3) println("Yes") else println("No")?

a)

Yes

b)

No

c)

Error

d)

Nothing

18.

Which of the following is a valid if-else syntax in Kotlin?

a)

if x > 0 { println(x) }

b)

if (x > 0) println(x) else println(-x)

c)

if x > 0 then println(x) else println(-x)

d)

if (x > 0): println(x) else: println(-x)

19.

What is the correct usage of the when expression in Kotlin?

a)

when x { 1 -> println("One") }

b)

when (x) { 1 -> println("One") }

c)

when x = 1 { println("One") }

d)

when (x: 1) { println("One") }

20.

What will the following code output if x is 2? when (x) { 1 -> "One" 2 -> "Two" else -> "Unknown" }

a)

"One"

b)

"Two"

c)

"Unknown"

d)

Error

21.

What will the following code output: var i = 0; while (i < 3) { println(i); i++ }?

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

Error

22.

Which of the following is the correct syntax for a while loop in Kotlin?

a)

while (condition) { // code }

b)

while condition { // code }

c)

while { condition // code }

d)

while (condition) // code

23.

What does the break statement do in a loop?

a)

Exits the loop

b)

Skips the current iteration

c)

Stops the program

d)

Restarts the loop

24.

What does the continue statement do in a loop?

a)

Exits the loop

b)

Skips to the next iteration

c)

Stops the program

d)

Restarts the loop

25.

Which keyword is used to define a function in Kotlin?

a)

func

b)

define

c)

fun

d)

method

26.

How do you declare a constant in Kotlin?

a)

const val

b)

let val

c)

val

d)

constant

27.

What will val result = 5 + 3 * 2 evaluate to?

a)

16

b)

11

c)

10

d)

8

28.

Which of the following is not a valid way to declare a string in Kotlin?

a)

val str = "Hello"

b)

val str = 'H'

c)

val str = """Hello"""

d)

val str = String("Hello")

29.

What will the following expression return: if (true) 1 else 0?

a)

0

b)

1

c)

true

d)

false

30.

What is the default value of an uninitialized variable in Kotlin?

a)

0

b)

null

c)

Undefined

d)

Error

31.

Which operator can be used to check for null values in Kotlin?

a)

?

b)

!

c)

&

d)

*

32.

What will val isEven = 4 % 2 == 0 evaluate to?

a)

true

b)

false

c)

0

d)

1

33.

How do you convert a string to an integer in Kotlin?

a)

str.toInt()

b)

Int(str)

c)

str.asInt()

d)

convert(str)

34.

What is the output of println("Hello" + "World")?

a)

Hello World

b)

HelloWorld

c)

Hello+World

d)

Error

35.

Which of the following correctly checks if a variable x is greater than 10?

a)

if x > 10

b)

if (x > 10)

c)

if [x > 10]

d)

if x: 10

36.

Which of the following is the correct syntax to declare an array in Kotlin?

a)

val arr = [1, 2, 3]

b)

val arr = arrayOf(1, 2, 3)

c)

val arr = new Array(3)

d)

val arr = List(1, 2, 3)

37.

What will val num = "123".toInt() return?

a)

"123"

b)

123

c)

Error

d)

0

38.

Which of the following keywords is used for type inference in Kotlin?

a)

var

b)

val

c)

let

d)

all of the above

39.

What is the output of println(5 == 5 && 5 != 6)?

a)

True

b)

False

c)

1

d)

0

40.

Which keyword is used to define a nullable type in Kotlin?

a)

?

b)

!

c)

*

d)

+

41.

What does the !! operator do in Kotlin?

a)

Converts to a non-null type

b)

Converts to a nullable type

c)

Throws an exception if null

d)

Both A and C

42.

Which of the following is a valid way to define a lambda function in Kotlin?

a)

val sum = { a: Int, b: Int -> a + b }

b)

val sum: (Int, Int) -> Int = { a, b -> a + b }

c)

Both A and B

d)

None of the above

43.

How do you handle exceptions in Kotlin?

a)

try-catch

b)

catch-try

c)

handle

d)

error

44.

What is the output of println(1.0 + 2)?

a)

3

b)

3.0

c)

Error

d)

3.00

45.

Which of the following is not a valid way to declare a variable?

a)

var x = 5

b)

val y: Int = 10

c)

let z = 15

d)

const w = 20

46.

What is the syntax for a basic while loop in Kotlin?

a)

while condition: { ... }

b)

while (condition) { ... }

c)

while { condition } { ... }

d)

loop while (condition) { ... }

47.

What happens if the condition in a while loop is never false?

a)

The loop will never execute.

b)

The loop will execute only once.

c)

The loop will run infinitely.

d)

An error will occur.

48.

What is the output of the following code?

var x = 0

while (x < 3) {

print(x)

x++

}

a)

123

b)

012

c)

321

d)

0123

49.

How can you terminate a while loop prematurely?

a)

Using exit.

b)

Using stop.

c)

Using terminate.

d)

Using break.

50.

What will happen if the condition in a while loop is initially false?

a)

The loop will execute once.

b)

The loop will execute twice.

c)

The loop will not execute at all.

d)

An error will be thrown.

51.

Which of the following is true about the while loop?

a)

It is used for iterating over arrays.

b)

It is used when the number of iterations is known beforehand.

c)

It is used when the number of iterations is unknown and depends on a condition.

d)

It can only be used for numerical operations.

52.

What is the output of the following code?

var n = 5

while (n > 0) {

n--

}

print(n)

a)

4

b)

0

c)

1

d)

5

53.

How do you skip the current iteration of a while loop and proceed to the next one?

(a)  

54.

Which of the following loops is guaranteed to run at least once?

a)

while loop

b)

do-while loop

c)

for loop

d)

foreach loop

55.

What is the purpose of the following code snippet?

var count = 0

while (true) {

println(count)

count++

if (count > 5) break

}

a)

Prints numbers from 0 to 6.

b)

Prints numbers from 1 to 5.

c)

Prints numbers from 0 to 5.

d)

Prints numbers from 1 to 6.

56.

What is the shorthand if-else syntax in Kotlin?

a)

condition ? expression1 : expression2

b)

if (condition) expression1 else expression2

c)

condition if expression1 else expression2

d)

condition ? expression1 else expression2

57.

Which of the following statements is true about shorthand if-else in Kotlin?

a)

It must be used with the ? operator.

b)

It can only be used with numeric expressions.

c)

It always returns a value.

d)

It cannot be used in variable assignments.

58.

What is the output of the following code?

val result = if (3 > 2) "True" else "False"

println(result)

a)

True

b)

False

c)

3 > 2

d)

An error will occur.

59.

Which of the following is the correct way to assign a value using shorthand if-else?

a)

val x = 5 > 3 ? "Yes" : "No"

b)

val x = if (5 > 3) "Yes" else "No"

c)

val x = 5 > 3 if "Yes" else "No"

d)

val x = (5 > 3) ? "Yes" : "No"

60.

Which of the following can be used as a return value from a function using shorthand if-else?

a)

Only String values.

b)

Only Int values.

c)

Any type of value.

d)

Only Boolean values

61.

What is the output of the following code?

val age = 18

val message = if (age >= 18) "Adult" else "Minor"

println(message)

a)

12

b)

Adult

c)

Minor

d)

An error will occur.

62.

What is the output of the following code?

val x = 5

val y = 10

val max = if (x > y) x else y

println(max)

a)

5

b)

10

c)

0

d)

An error will occur.

63.

How can you simplify this code using shorthand if-else?

val number = -5

val status = if (number >= 0) "Positive" else "Negative"

a)

val status = number >= 0 ? "Positive" : "Negative"

b)

val status = number if >= 0 "Positive" else "Negative"

c)

val status = if (number >= 0) "Positive" else "Negative"

d)

val status = number >= 0 then "Positive" else "Negative"

64.

What is the result of the following code?

fun checkNumber(num: Int) = if (num > 0) "Positive" else "Negative"

val result = checkNumber(-10)

println(result)

a)

Positive

b)

Negative

c)

0

d)

An error will occur.

65.

Which of the following is the correct syntax for a basic when expression in Kotlin?

a)

when (expression) { ... }

b)

when { expression -> ... }

c)

when: expression { ... }

d)

switch (expression) { ... }

66.

What is the output of the following code?

val day = 3

val result = when (day) {

1 -> "Monday"

2 -> "Tuesday"

3 -> "Wednesday"

else -> "Invalid day"

}

println(result)

a)

Monday

b)

Tuesday

c)

Wednesday

d)

Invalid day

67.

Which of the following is true about the else branch in a when expression?

a)

It is mandatory.

b)

It is used as a default case.

c)

It must be the first branch.

d)

It can only be used with numeric types.

68.

What is the output of the following code?

val x = 10

val result = when {

x < 5 -> "Low"

x in 5..15 -> "Medium"

else -> "High"

}

println(result)

a)

Low

b)

Medium

c)

High

d)

An error will occur.

69.

What is the output of the following code?

val result = when ("Hello") {

"Hi" -> "Greeting"

"Bye" -> "Farewell"

"Hello" -> "Salutation"

else -> "Unknown"

}

println(result)

a)

Greeting

b)

Farewell

c)

Salutation

d)

Unknown

70.

Which of the following statements is true about the when expression in Kotlin?

a)

It can only be used with numbers.

b)

It can be used as a statement or as an expression.

c)

It always requires an else branch.

d)

It cannot return a value.