9.2.1. Inheritance
//The Vehicle class....
class Vehicle{
var type:String
init(type:String){
self.type = type
}
}
// defining a new class inheriting Vehicle class
class Car:Vehicle{
var make:String
var model:String
init(type:String, make:String, model:String) {
//initializing this instance's properties...
self.make = make
self.model = model
//Calling super class's initializer...
super.init(type: type)
}
}Overriding methods
Source code
Last updated