Bird
0
0

What keyword is used in Kotlin to declare a function as an operator?

easy📝 Conceptual Q2 of 15
Kotlin - Operators and Expressions
What keyword is used in Kotlin to declare a function as an operator?
Aoverride
Bfun
Coperator
Dinline
Step-by-Step Solution
Solution:
  1. Step 1: Identify the keyword for operator functions

    Kotlin requires the keyword 'operator' before a function to mark it as an operator overload.
  2. Step 2: Differentiate from other keywords

    'fun' declares a function, but 'operator' specifically enables operator overloading.
  3. Final Answer:

    operator -> Option C
  4. Quick Check:

    Keyword for operator functions = operator [OK]
Quick Trick: Use 'operator' keyword to enable operator overloading [OK]
Common Mistakes:
MISTAKES
  • Using only 'fun' without 'operator'
  • Confusing 'override' with 'operator'
  • Assuming 'inline' enables operator overloading

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes