-
Book Overview & Buying
-
Table Of Contents
Android Programming for Beginners - Fourth Edition
By :
Just like it sounds, inheritance lets us leverage the features and benefits of other people's classes (including encapsulation and polymorphism) while further refining their code for our specific situation.
We have done this already every time we used the : operator as shown highlighted below:
class MainActivity : ComponentActivity() ...
The preceding line of code makes our MainActivity class inherit from the ComponentActivity class. Furthermore, the ComponentActivity class itself inherits from the Activity class. So, we inherited from ComponentActivity and, by extension, from Activity every time we created a new Android project.
Imagine if the world's strongest man got together with the world's most intelligent woman. There is a good chance that their children will benefit profoundly from genetic inheritance. Inheritance in Kotlin lets us do the same thing with someone else's code and our own.
When used carefully, all this OOP lets...