Computer scienceProgramming languagesKotlinObject-oriented programmingClass hierarchy

Functional (SAM) interfaces

Defining a Functional (SAM) Interface

Report a typo

Write a Kotlin program that defines a functional (SAM) interface named Operation. This interface should include a single abstract method execute that accepts two integers and returns another integer.

Create a function called performOperation, which accepts two integers and an instance of Operation and then returns the result of the operation.

Sample Input 1:

1 2

Sample Output 1:

3
Write a program in Kotlin
fun interface Operation {
// make your code here
}

fun performOperation(a: Int, b: Int, operation: Operation): Int {
// make your code here
}
___

Create a free account to access the full topic