Bird
0
0

Consider this Kotlin code:

medium📝 Predict Output Q5 of 15
Kotlin - Functions
Consider this Kotlin code:
fun isPositive(n: Int) = n > 0
println(isPositive(-3))

What is the output?
Atrue
Bnull
CCompilation error
Dfalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function logic

    The function returns true if n is greater than 0, otherwise false.
  2. Step 2: Evaluate for input -3

    -3 is not greater than 0, so the function returns false, which is printed.
  3. Final Answer:

    false -> Option D
  4. Quick Check:

    isPositive(-3) = false [OK]
Quick Trick: Check if number > 0 returns true else false [OK]
Common Mistakes:
MISTAKES
  • Assuming negative numbers return true
  • Confusing boolean output with string
  • Expecting compilation error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes