풍's토리

반응형

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)