-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5장] 클래스와 인터페이스 #7
Comments
퀴즈 내용 객관식의 정답을 골라보세요.
퀴즈 정답
정답은 3번
1번 : 인터페이스는 extends라는 키워드를 사용해 확장할 수 있으며 클래스에서는 extends 키워드로 선언할 수 있습니다. 2번 : 타입 별칭의 경우, 오른편에는 타입 별칭을 포함한 모든 타입이 올 수 있습니다. 인터페이스의 경우 오른편에는 반드시 형태가 나와야합 니다. |
다음 중 옳지 않은 것을 고르세요!
퀴즈 정답
정답은 (3)번!
(1). 타입 별칭은 더 일반적입니다. 타입 별칭의 오른쪽에는 타입 표현식(타입과 &, ㅣ연산자)를 포함한 모든 타입이 등장합니다. 반면, 인터페이스는 오른편에 형태가 나와야 합니다. (2) 인터페이스를 상속하면 상속받는 인터페이스 타입에 상위 인터페이스 할당이 가능한지 확인합니다, 타입 별칭과 인터섹션을 사용하면 타입을 조합하는 방향으로 사용됩니다. (3) 이름과 범위가 같은 인터페이스는 자동으로 합쳐집니다. 타입 별칭은 컴파일 타임 에러를 방출합니다. 이를 선언 합침(declaration merging)이라 칭합니다. 112~113페이지 참조 |
클래스 생성자를 class Person {
name;
protected constructor(name) {
this.name = name;
}
}
new Person('dahye') 퀴즈 정답다음과 같은 타입 에러가 출력됩니다. 해당 클래스는 바로 인스턴스화 될 수 없습니다. 상속받은 하위클래스에서 class Person {
name;
protected constructor(name) {
this.name = name;
}
}
class Dahye extends Person {
name;
constructor(name) {
super(name);
}
}
const dahye = new Dahye('dahye'); |
interface Animal {
bark(text: string): void;
}
class Dog implements Animal {
bark(text) {
...
}
} 퀴즈 정답implements는 클래스나 메서드의 타입을 바꾸지않고, 확인만 한다. 따라서 Dog 클래스 메서드인 bark의 파라미터 인자를 string으로 맞춰주어야한다. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[5장 퀴즈]
클래스와 인터페이스
아래 마크다운을 복사 붙여넣기해서 코멘트로 퀴즈를 달아주세요 :)
객관식, 주관식에 상관없이 편하게 만들어주세요!
부가 설명을 달고 싶다면, 해설을 정답과 함께 옵션으로 작성하시면 됩니다.☺️
예시
The text was updated successfully, but these errors were encountered: