Classes using the Inheritance example app
We have looked at the way we can create hierarchies of classes to model the system that fits our app. So, let's build a project to improve upon the naval battle we had in the previous chapter.
Create a new project called Basic Classes with
Inheritance Example
using the Empty Activity template. As you have come to expect, the completed code can be found in the Chapter11
folder.
This is what we are going to do:
- Put most of the functionality of the
Carrier
andDestroyer
classes into aShip
super class. - Inherit from the
Ship
class for bothCarrier
andDestroyer
, and therefore save a lot of code maintenance. - Use polymorphism to adapt the
serviceShip
function in theShipyard
class so that it takesShip
as a parameter, ...
Get Android Programming with Kotlin for Beginners now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.