Created
November 5, 2014 04:37
-
-
Save Ryusuke-Kawasaki/12de369253689003f106 to your computer and use it in GitHub Desktop.
Inheritance6.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Person { | |
var name = "" | |
var age = 0 | |
//イニシャライザ | |
init(){ | |
self.name = "unknown" | |
self.age = 20 | |
} | |
//パラメータ付きイニシャライザ | |
init(name:String,age:Int){ | |
self.name = name | |
self.age = age | |
} | |
//インスタンスメソッド | |
func printSelfIntroduction(){ | |
println("私の名前は\(self.name)です。年齢は\(self.age)歳です。") | |
} | |
//デイニシャライザ | |
deinit { | |
println("deinit call") | |
} | |
//タイプメソッド | |
class func printPersonInfo() { | |
println("Personクラスは人の情報を定義したクラスです") | |
} | |
} | |
//コンパイルエラー | |
class Student : Person{ | |
var no = 0 | |
func printNo(){ | |
println("出席番号は\(self.no)です。") | |
} | |
//コンパイルエラー | |
override func printSelfIntroduction() { | |
super.printSelfIntroduction() | |
printNo() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment