Recall & Review
beginner
What is an extension function in Kotlin?
An extension function lets you add a new function to an existing class without changing its source code. It helps you extend functionality easily.Click to reveal answer
beginner
How do you declare an extension function in Kotlin?
You write the receiver type followed by a dot and the function name. For example:
fun String.shout() = this.uppercase() + "!"Click to reveal answer
intermediate
Can extension functions access private members of the class they extend?No, extension functions cannot access private or protected members of the class. They work like regular functions with the receiver object as a parameter.
Click to reveal answer
intermediate
What happens if an extension function has the same signature as a member function?
The member function always takes precedence over the extension function when called on an instance.
Click to reveal answer
beginner
Why are extension functions useful in Android development?
They let you add helpful functions to Android classes like View or Context without subclassing, making code cleaner and easier to read.Click to reveal answer
How do you call an extension function on a String named
text?✗ Incorrect
Extension functions are called like regular functions on the object, e.g.,
text.extensionFunction().Which keyword is used to declare an extension function in Kotlin?
✗ Incorrect
Extension functions are declared with the
fun keyword followed by the receiver type.Can extension functions modify the state of the object they extend?
✗ Incorrect
Extension functions can modify the object if it is mutable, like a mutable list.
What is the receiver in an extension function?
✗ Incorrect
The receiver is the type of the object the extension function is adding functionality to.
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.
Explain what an extension function is and how it can be declared in Kotlin.
Think about adding new functions to existing classes without changing them.
You got /3 concepts.
Describe the rules about access and precedence when using extension functions in Kotlin.
Consider what happens if a class already has a function with the same name.
You got /3 concepts.