Swift
[Swift] 11. 클래스
CodingKwon
2021. 10. 6. 23:16
1. 클래스
클래스는 참조 타입
타입 이름은 대문자 카멜케이스를 사용
class 이름 {
/* 구현부 */
}
- 클래스의 타입 메서드는 두 가지 종류가 있음
- 1. 상속 후 재정의가 가능한 class 타입 매서드
- 2. 상속 후 재정의가 불가능한 static 타입 매서드
class Sample {
// 가변 프로퍼티
var mutableProperty: Int = 100
// 불변 프로퍼티
let immutableProperty: Int = 100
// 타입 프로퍼티
static var typeProperty: Int = 100
// 인스턴스 메서드
func instanceMethod() {
print("instance method")
}
// 타입 메서드
// 재정의 불가 타입 메서드 - static
static func typeMethod() {
print("type method - static")
}
// 재정의 가능 타입 메서드 - class
class func classMethod() {
print("type method - class")
}
}