October 2018
Intermediate to advanced
370 pages
9h 15m
English
Like normal classes, the object class can also make the most of the benefits of inheritance. We can create a normal parent class that can be extended by the object class. In the following example, we have a class called Parent with one callMySingleton function. We also have one MySingleton object class, which extends the parent class. The MySingleton class overrides the callMySingleton() function:
open class Parent { open fun callMySingleton(){ println("Parent class is called") } } object MySingleton : Parent() { override fun callMySingleton(){ super.callMySingleton() println("my Singleton class is called") } }
In the main function, we use a single instance of the object class, call the ...
Read now
Unlock full access