マル開発日記

マルAndroidデベロッパ

継承

 

田中はエスパーになりました。イトウの方がいいかな??

 

import UIKit

 

class Human {

    let name :String

    let age :UInt8

    

    init(name :String, age :UInt8){

        self.name = name

        self.age = age

    }

    

    func introduce() {

        print("My name is \(name).")

        print("I am \(age) years old.")

    }

}

 

class Esper :Human {

    override func introduce() {

        super.introduce()

        print("I am a Esper!")

    }

}

 

var sato = Human(name: "sato", age: 77)

sato.introduce()

 

var tanaka = Esper(name: "tanaka", age: 90)

tanaka.introduce()