Recall & Review
beginner
How do you declare a simple function in Kotlin that takes no parameters and returns no value?
Use the
fun keyword followed by the function name and empty parentheses. For example: <br>fun greet() {<br> println("Hello!")<br>}Click to reveal answer
beginner
What is the syntax to declare a Kotlin function that returns an integer?
Specify the return type after the parameter list with a colon. For example: <br>
fun add(a: Int, b: Int): Int {<br> return a + b<br>}Click to reveal answer
beginner
How do you declare a Kotlin function with parameters?
Inside the parentheses after the function name, list parameters with their names and types separated by commas. For example: <br>
fun greet(name: String) {<br> println("Hello, $name!")<br>}Click to reveal answer
intermediate
What is a single-expression function in Kotlin and how is it declared?
A function that returns a single expression can be declared using the = sign without curly braces. For example: <br>
fun square(x: Int): Int = x * x
Click to reveal answer
intermediate
Can Kotlin functions have default parameter values? How do you declare them?
Yes, you can assign default values to parameters in the declaration. For example: <br>
fun greet(name: String = "Guest") {<br> println("Hello, $name!")<br>}Click to reveal answer
Which keyword is used to declare a function in Kotlin?
✗ Incorrect
In Kotlin, the keyword
fun is used to declare functions.How do you specify the return type of a Kotlin function?
✗ Incorrect
The return type is specified after the parameter list with a colon, like
fun f(): Int.What is the correct way to declare a function with a single expression in Kotlin?
✗ Incorrect
Single-expression functions use = followed by the expression, no curly braces needed.
How do you provide a default value for a function parameter in Kotlin?
✗ Incorrect
Default values are assigned with = after the parameter type, e.g.,
name: String = "Guest".Which of these is a valid Kotlin function declaration?
✗ Incorrect
Only
fun is the correct keyword for Kotlin function declarations.Explain how to declare a Kotlin function with parameters and a return type.
Think about the order: fun, name, parameters, return type, then body.
You got /5 concepts.
Describe what a single-expression function is in Kotlin and how to write one.
It's a short way to write functions that return one thing.
You got /4 concepts.