Bird
0
0

Identify the error in this Kotlin function declaration:

medium📝 Debug Q6 of 15
Kotlin - Functions
Identify the error in this Kotlin function declaration:
fun add(a: Int, b: Int) {
    return a + b
}
AMissing return type declaration
BIncorrect parameter types
CFunction name is invalid
DReturn statement syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Check function signature

    The function returns a value but does not declare a return type after the parameter list.
  2. Step 2: Understand Kotlin return type requirement

    If a function returns a value, its return type must be declared explicitly, e.g., : Int.
  3. Final Answer:

    Missing return type declaration -> Option A
  4. Quick Check:

    Return type must be declared if function returns a value [OK]
Quick Trick: Declare return type when function returns a value [OK]
Common Mistakes:
MISTAKES
  • Omitting return type when returning a value
  • Using return in void functions
  • Incorrect function name spelling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes