Recall & Review
beginner
What happens when a Kotlin class has both a member function and an extension function with the same name?The member function always has higher priority and will be called instead of the extension function.
Click to reveal answer
beginner
Can extension functions override member functions in Kotlin?
No, extension functions cannot override member functions. Member functions take precedence even if an extension function has the same signature.
Click to reveal answer
intermediate
Why do member functions have priority over extension functions in Kotlin?
Because member functions are part of the class definition and have direct access to the class internals, Kotlin always prefers them over extensions which are resolved statically.Click to reveal answer
intermediate
How are extension functions resolved in Kotlin?
Extension functions are resolved statically based on the declared type of the variable, not the runtime type.
Click to reveal answer
beginner
What is a practical use case for extension functions despite member functions having priority?
Extension functions allow adding new functionality to classes without modifying their source code, especially useful for classes from libraries or the Kotlin standard library.
Click to reveal answer
In Kotlin, if a class has a member function and an extension function with the same name, which one is called?
✗ Incorrect
Member functions have higher priority and are called instead of extension functions with the same name.
Can extension functions override existing member functions in Kotlin?
✗ Incorrect
Extension functions cannot override member functions; member functions always take precedence.
How are extension functions resolved in Kotlin?
✗ Incorrect
Extension functions are resolved statically using the declared type of the variable.
Why might you use an extension function in Kotlin?
✗ Incorrect
Extension functions let you add new functions to classes without changing their source code.
If a variable is declared as a superclass type but holds a subclass instance, which extension function is called?
✗ Incorrect
Extension functions are resolved based on the declared type, so the superclass extension function is called.
Explain the priority between member functions and extension functions in Kotlin and why it matters.
Think about how Kotlin decides which function to call when names clash.
You got /3 concepts.
Describe how extension functions are resolved in Kotlin and how this affects their behavior compared to member functions.
Consider the difference between compile-time and runtime decisions.
You got /3 concepts.