Super
-
javaScript 클래스(+ 프로퍼티 getter와 setter / 상속)Front/js 2024. 7. 4. 17:08
▤ 목차">HTML 삽입미리보기할 수 없는 소스 함수형 프로그래밍 언어인 javascript에서 최근 클래스의 개념이 나왔다.java에서 클래스와는 차이가 있다. 그 차이를 위주로 정리해보려고한다.java가 익숙한 사람은 java와 비슷한 부분이 있기에 금방 익숙해 질 수 있다고 개인적으로 생각한다. ✔ 클래스클래스는 OOP에서 특정 객체를 생성하기 위해 멤버를 정의하는 일종의 틀(설계도)을 말한다.기존의 PROTOTYPE을 기반으로 객체를 생성하는 것보다 명료하게 객체 작성이 가능하다.클래스도 함수와 같이 호출하기 전까지는 코드가 실행되지 않는다. ⌨ 형식class 클래스명{ 멤버 변수; constructor(){} // 생성자 메소드명(){}; //메서드} JAVA와 비교..
-
메소드 재정의(Override)와 부모 메소드 호출(super)JAVA/클래스,상속,인터페이스,기본API 2024. 6. 5. 10:47
▤ 목차" data-ke-type="html">HTML 삽입미리보기할 수 없는 소스 상속을 받아 사용하면서 자식 클래스에서 사용하기 적합하지 않을 수 있다.상속된 일부 메서드는 자식 클래스에서 다시 수정해서 사용해야 한다.이런 경우, 재정의 할 수 있는데 이를 메서드 오버라이드라고 한다.✔ 오버라이드?상속된 메서드의 내용이 자식 클래스에 맞지 않을 경우, 자식 클래스에서 동일한 메서드를 재정의 하는 것을 말한다.편하게 말하자면 부모의 정의가 마음에 들지 않으면 자식 클래스에서 다시 정의하는 것이다.대신, 오버라이드를 하기 위해서는 규칙이 있다.아래 규칙으로 인해 오버라이딩이 되었다면 부모 객체의 메서드는 숨겨지기 때문에메서드를 호출하면 오버라이딩 된 자식의 메서드가 호출된다.⌨ 규칙접근 제한을 더 강하게..