Skip to content

Instantly share code, notes, and snippets.

@Ryusuke-Kawasaki
Created November 5, 2014 04:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ryusuke-Kawasaki/12de369253689003f106 to your computer and use it in GitHub Desktop.
Save Ryusuke-Kawasaki/12de369253689003f106 to your computer and use it in GitHub Desktop.
Inheritance6.swift
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