Language93 Super 'super' keyword is used to refer to the parent class. It is generally used with methods and variables, and is also used in constructors. Here is an example with methods: class ParentClass { void display() { System.out.println("This is the parent class"); } } class ChildClass extends ParentClass { void display() { System.out.println("This is the child class"); } void printMsg() { // Calling the d.. 2023. 5. 11. 다형성(Polymorphism) 객체 지향 프로그래밍의 특징에는 추상화, 상속, 다형성, 캡슐화가 있다. 그 중 객체 지향 프로그래밍의 꽃이라고 할 수 있는 다형성에 대해 한번 정리하고 가려한다. 다형성이란 어떤 객체의 속성이나 기능이 상황에 따라 여러 가지 형태를 가실 수 있는 성질을 의미한다. 설명보다는 코드로 한번 보는게 훨씬 이해가 빨라진다. class Animal { public void makeSound() { System.out.println("The animal makes a sound"); } } class Dog extends Animal { @Override public void makeSound() { System.out.println("The dog barks"); } } class Cat extends Anim.. 2023. 5. 7. Partial 타입 interface Profile { name: string; age: number; married: boolean; } const lee: Profile = { name: "lee", age: 30, married: true, }; 위 인터페이스에서 각 프로퍼티를 필수가 아닌 선택이 되도록 하고 싶을때 Partial 타입을 사용할 수 있다. 사용예시 const kim: Partial = { name: "kim", age: 25, }; Partial 타입의 정의는 다음과 같다 type Partial = { [P in keyof T]?: T[P]; }; 각 프로퍼티마다 Optional(물음표)를 붙여주는데 앞서 배운 Index signature와 Mapped types 그리고 괄호표기법을 활용하여 정의하였다.. 2023. 3. 19. 공변성과 반공변성 공변성과 반공변성.. 용어부터가 뭔가 어렵다 강의 들어봤는데 이해하려고 하면 할수록 더 복잡해지는 개념이기에 결론만 기억하고 사용하면 될 것 같다 공변성과 반공변성은 함수 간의 대입에서 나온 개념이다. function a(x: string): number { return +x; } type B = (x: string) => number | string; const b: B = a; 위와 같이 리턴 값은 더 넓은 타입으로 대입이 가능하다. 리턴 값을 넓은 타입에서 좁은 타입으로 대입 하는 것은 불가능하다. function d(x: string): number | string { return +x; } type C = (x: string) => number; const c: C = d; // ERROR 그리.. 2023. 3. 18. 이전 1 ··· 7 8 9 10 11 12 13 ··· 24 다음