0
0
Kotlinprogramming~20 mins

Kotlin REPL and script mode - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kotlin REPL and Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of variable reassignment in Kotlin REPL
What is the output of the following Kotlin REPL session?
Kotlin
var x = 5
x = x + 3
println(x)
A8
B5
CCompilation error
DRuntime exception
Attempts:
2 left
💡 Hint
Remember that 'var' allows reassignment in Kotlin.
Predict Output
intermediate
2:00remaining
Script mode output with top-level function
What will be printed when running this Kotlin script file?
Kotlin
fun greet(name: String) {
    println("Hello, $name!")
}
greet("Alice")
ANo output
Bgreet
CCompilation error: function must be inside a class
DHello, Alice!
Attempts:
2 left
💡 Hint
Kotlin scripts allow top-level functions and execute statements immediately.
Predict Output
advanced
2:00remaining
REPL session with shadowing and type inference
What is the output of this Kotlin REPL session?
Kotlin
val x = 10
val x = "Ten"
println(x)
ATen
B10
CCompilation error: val x already defined
DRuntime exception
Attempts:
2 left
💡 Hint
In Kotlin REPL, you can shadow previous variables by redeclaring them.
Predict Output
advanced
2:00remaining
Script mode with top-level statements and variable scope
What will be the output of this Kotlin script?
Kotlin
val a = 5
fun printA() {
    val a = 10
    println(a)
}
printA()
println(a)
ACompilation error: variable a redeclared
B
5
10
C
10
5
D
10
10
Attempts:
2 left
💡 Hint
Local variables inside functions shadow outer variables.
🧠 Conceptual
expert
2:00remaining
Difference between Kotlin REPL and script mode execution
Which statement correctly describes a key difference between Kotlin REPL and Kotlin script mode?
AKotlin REPL does not support variable reassignment, but script mode does.
BKotlin REPL executes code line-by-line interactively, while script mode runs the entire file as a single unit.
CKotlin REPL compiles to JVM bytecode, but script mode runs only interpreted code.
DKotlin REPL requires all code inside functions, but script mode allows top-level statements.
Attempts:
2 left
💡 Hint
Think about how REPL and scripts handle code execution timing.