Inheritance
Create the parent class
Class Dog
{
let numLegs: Int
init(numLegs: Int)
{
self.numLegs = numLegs
}
}
Inherit the parent class
Class Chihuahua: Dog
{
let size = "Small"
}
Instantiating the child class:
var myChihuahua = Chihuahua(numLegs: 4)
myChihuahua.numLegs
Notes:
- Used when a class inherits the properties and functions of a parent class
- Child class will also inherit constructor of parent class
Class Dog
{
let numLegs: Int
init(numLegs: Int)
{
self.numLegs = numLegs
}
}
Inherit the parent class
Class Chihuahua: Dog
{
let size = "Small"
}
Instantiating the child class:
var myChihuahua = Chihuahua(numLegs: 4)
myChihuahua.numLegs
Notes:
- Used when a class inherits the properties and functions of a parent class
- Child class will also inherit constructor of parent class
Comments
Post a Comment