[ios] swift 체험하기 #5 클래스
import UIKit
var str = "Hello, playground"
//super(parent) class
class BookInfo {
var title = ""
var author = ""
func printTitle() {
print("Title is " + title)
}
}
//child class
class BookInfoSub : BookInfo {
var subTitle = ""
override func printTitle() {
super.printTitle()
print("subTitle is \(subTitle)")
}
}
let bInfo = BookInfo()
bInfo.title = "Test"
bInfo.author = "Me"
let bInfo2 = BookInfo()
bInfo2.title = "Test2"
bInfo2.author = "Who"
print(bInfo.title)
bInfo.printTitle()
print(bInfo.author)
print(bInfo2.title)
print(bInfo2.author)
let bInfo3 = BookInfoSub()
bInfo3.title = "Test3"
bInfo3.subTitle = "subTest"
bInfo3.author = "unknown"
print(bInfo3.title)
bInfo3.printTitle()
print(bInfo3.author)
print(bInfo3.subTitle)
'메뉴 일곱' 카테고리의 다른 글
[ios] swift 체험하기 #6 클래스2 & 옵셔널 (0) | 2019.04.11 |
---|---|
[ios] swift 체험하기 #4 함수 (0) | 2019.04.09 |
[ios] swift 체험하기 #3 반복문 (0) | 2019.04.08 |