티스토리 뷰

배움과 복습

2017-09-01 금요일: 7.상속

뚜비콩 2017. 9. 1. 10:17

1. has a 관계

class B{
A a = new A();
a.method1();
}

A a = new A(); //가능
B b = new B(); //가능
A aa = new B();     //불가능
B bb = new A();    //불가능

2. is a 관계

class B extends A {
method1();
}

A a = new A();

B b = new B();

A aa = new B();        //여기까지 가능!

B bb = new A();         //불가능 =>자식타입의 부모? 만들어질 수 없습니다.


3. class / interface(완전추상) 

class A extends B //끝 : 단일추상

interface a extends interface1, interface2, ... //다중추상 가능

4. implements

Class extends Class implements interface1, interface2, ....
부모와 자식 간의 타입이 다르면 implements로 받습니다.
부모가 interface라면 다수개의 상속도 가능합니다.         //class 불가능

5. final

1) 필드: 변하지 않는 수(상수)
2) 메서드: 변하지 않는 메서드(재정의 불가)
3) 클래스: 변하지 않는 클래스(상속불가)

6. protected 접근 제한자

7. 타입 변환과 다형성

자동 타입 변환(Promotion)


'배움과 복습' 카테고리의 다른 글

abstract class  (0) 2017.09.01
Abstract class에 대해  (0) 2017.09.01
Getter와 Setter, 그리고 private타입  (0) 2017.08.31
2017-08-31 목요일 : 수요일 과제 리뷰  (0) 2017.08.31
2017-08-30 수요일 : 정렬(sort)  (0) 2017.08.30
댓글