객체지향 프로그래밍 with 자바

준비중..

객체지향 프로그래밍 with 자바

객체를 조립하여 프로그램 만드는 법!

35 연습문제F - 상속과 인터페이스

# 연습문제 F - 상속과 인터페이스 ## 상속 <div class="embed-responsive embed-responsive-16by9"> <iframe src="https://www.youtube.com/embed/v1GUnFomGbY" frameborder="0" allowfullscreen></iframe> </div> ## 인터페이스 <div class="embed-responsive embed-responsive-16by9"> <iframe src="https://www.youtube.com/embed/Wuyr_X7CKCU" frameborder="0" allowfullscreen></iframe> </div> ## 15 상속 --- #### 상속이란 - 기존 클래스를 확장하여 새 클래스를 만드는 것 - 중복 코드를 줄일 수 있는 장점이 있음 - extends 키워드로 구현 - 코드의 재사용성 증가 #### 업 캐스팅과 오버라이딩 - 업 캐스팅 - 자식 객체를 부모의 타입으로 해석하는 것 - 메소드 오버라이딩 - 부모의 메소드를 자식 클래스에서 재정의 하는 것 #### protected와 super - protected - 상속 관계 시 접근 허용 - super - 부모 객체를 의미하는 키워드(↔ this는 자기 자신) ## 16 인터페이스 --- #### 인터페이스란 - 인터페이스란, 역할을 부여하는 것이다. - 인터페이스는 프로토타입 메소드를 가진다. - 프로토타입 메소드란 중괄호 내부가 없는 즉, 메소드 실행영역이 없는 껍데기 메소드이다. #### 인터페이스의 구현 - 인터페이스 구현 시, implements 키워드를 사용한다. - 해당 인터페이스(역할)를 구현하는(부여받은) 클래스를 구현체 클래스라 한다. - 구현체 클래스는 반드시 인터페이스에 명시된 메소드를 오버라이딩(재정의)해야 한다 #### 타입으로서의 인터페이스 - 구현체 클래스의 객체는 인터페이스 타입으로 해석될 수 있다 - 이를 통해, 다양한 클래스를 같은 인터페이스로 그룹화가 가능하다 ## 17 추상 클래스 --- #### 추상 클래스란 - 개념적 클래스로, 직접적 객체 생성이 불가능 - abstract 키워드를 클래스에 붙여 선언 #### 추상 클래스의 장점 - 상속을 통해 중복 코드를 줄일 수 있다 - 자식 클래스를 그룹화할 수 있다 - 비 실존 객체의 직접 생성을 사전에 차단하여 실수 방지가 가능하다 ## 확인하기 --- <div class="interact_responsive_padding" style="padding:100% 0 0 0;position:relative;margin-bottom:5px;"><div class="interact_responsive_wrapper" style="height:100%;left:0;position:absolute;top:0;width:100%;"><iframe id="interactApp5d36e8958105ff00146fc972" width="100%" height="100%" style="border:none;max-width:100%;margin:0;" allowTransparency="true" frameborder="0" src="https://quiz.tryinteract.com/#/5d36e8958105ff00146fc972/q/1?method=iframe"></iframe></div></div>

Challenge

개념 실습! 학습 내용을 진짜 내 것으로 만들기!