February 2018
Intermediate to advanced
350 pages
7h 35m
English
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 ...
Read now
Unlock full access