October 2018
Intermediate to advanced
370 pages
9h 15m
English
Kotlin does not allow multiple inheritance, but it does allow classes with more than one interface. To understand the concept of multiple interfaces, let's take the example of a Calculator class. There are few basic operations that every calculator performs—add, subtract, multiply, and divide. We can create an interface for each operation and let the class implement as many interfaces as it wants:
interface IAdd { fun add(a : Int, b : Int) } interface ISubtract { fun subtract(a : Int, b : Int) } interface IMultiply { fun multiply(a : Int, b : Int) } interface IDivide{ fun divide(a : Int, b : Int) }
Now, each class must follow the rules and define the same function name and parameters that are defined in the interface. ...
Read now
Unlock full access