구조체와 상당히 유사한데 구조체는 값타입이지만 클래스는 참조타입이라는 점이 크게 다른점이다. 클래스는 다중 상속이 되지 않는다는 점을 기억해두자.
구조체와는 다르게 내부에서 선언한 let에 대하여 var 과 let으로 선언한후 둘다 값변경이 가능하다.
// 인스턴스 생성 - 참조정보 수정 가능
var mutableReference: Sample = Sample()
mutableReference.mutableProperty = 200
// 불변 프로퍼티는 인스턴스 생성 후 수정할 수 없다
// 컴파일 오류 발생
//mutableReference.immutableProperty = 200
// 인스턴스 생성 - 참조정보 수정 불가
let immutableReference: Sample = Sample()
// 클래스의 인스턴스는 참조 타입이므로 let으로 선언되었더라도 인스턴스 프로퍼티의 값 변경이 가능하다
immutableReference.mutableProperty = 200// 구조체와 다른점
// 다만 참조정보를 변경할 수는 없다
// 컴파일 오류 발생
//immutableReference = mutableReference
// 참조 타입이라도 불변 인스턴스는
// 인스턴스 생성 후에 수정할 수 없다
// 컴파일 오류 발생
//immutableReference.immutableProperty = 200
// 타입 프로퍼티 및 메서드
Sample.typeProperty = 300
Sample.typeMethod() // type method
// 인스턴스에서는 타입 프로퍼티나 타입 메서드를
// 사용할 수 없다
// 컴파일 오류 발생
//mutableReference.typeProperty = 400
//mutableReference.typeMethod()