Kotlin allows you to nest functions, one within another. We can declare and use a function within another function.
When you declare a function within another function, the nested functions, visibility will stay exclusively within the parent function and cannot be accessed from outside.
So, let's have an example:
fun main(args: Array<String>) { fun nested():String { return "String from nested function" } println("Nested Output: ${nested()}") }
In the preceding program, we declared and used a function—nested()—inside the main function.
The following is the output, if you're curious:
So, as we've got our basics brushed up in functions, let's move forward in functional programming. In the following section, we will learn about function types.