February 2018
Intermediate to advanced
350 pages
7h 35m
English
In Kotlin, a class's behavior is defined by methods. Technically, a method is a member function, so, anything that we learn about functions in the following chapters also applies to the methods:
class Cupcake(val flavour: String) { fun eat(): String { return "nom, nom, nom... delicious $flavour cupcake" }}
The eat() method returns a String value. Now, let's call the eat() method, as shown in the following code:
fun main(args: Array<String>) { val myBlueberryCupcake = Cupcake("Blueberry") println(myBlueberryCupcake.eat())}
The following expression is the output of the preceding code:
Nothing mind-blowing, but this is our first method. ...
Read now
Unlock full access