import UIKit
//** Inheritance
//** extends개념과 동일
class Car {
var numWheels = 4
//** 初期化
init(numWheels: Int) {
self.numWheels = numWheels
}
}
//** Like extends
//** Car classのnumWheelsがextends
class FamilyCar: Car {
var numDoors = 5
}
//** FamilCar classのnumDoorsがextends
//** Car classのnumWheelsがextends
class BigFamilyCar: FamilyCar {
var size = "Large"
}
//** Object生成
var myFamCar = FamilyCar(numWheels: 6)
myFamCar.numWheels
myFamCar.numDoors
//** extendsしたClassの内に初期化関数(init)のパラメーターがあると入力が必要。
var bigFamCar = BigFamilyCar(numWheels: 2)
bigFamCar.size
댓글 없음 :
댓글 쓰기