Android 프로그래밍 2

본문 바로가기
사이트 내 전체검색


Android 프로그래밍 2
Android 프로그래밍 2

3. 다중 상속

페이지 정보

작성자 관리자 댓글 0건 조회 1,918회 작성일 20-03-22 21:47

본문

3. 다중 상속

추상클래스는 단일 상속만 가능한데 인터페이스는 여러개의 인터페이스를 구현할수 있다. 즉 다중 상속이 가능하다.


실습.


fun main (args :Array<String>) {
    var tempClass1 : Interface1 = TempClass()
    tempClass1.generalMethod1()
    tempClass1.abstractMethod1()

    var tempClass2 : Interface2 = TempClass()
    tempClass2.generalMethod2()
    tempClass2.abstractMethod2()
}

interface Interface1 {
    fun generalMethod1() {
        println("Interface1 에서 구현된 일반 메서드 입니다")
    }
    fun abstractMethod1()
}

interface Interface2 {
    fun generalMethod2() {
        println("Interface2 에서 구현된 일반 메서드 입니다")
    }
    fun abstractMethod2()
}

class TempClass : Interface1, Interface2 {
    override fun abstractMethod1() {
        println("TempClass 에서 구현된 Interface1의 추상 메서드 입니다")
    }

    override fun abstractMethod2() {
        println("TempClass 에서 구현된 Interface2의 추상 메서드 입니다")
    }
}


TempClass를 보면 Interface1, Interface2 두개의 인터페이스가 구현되어 있는 걸 볼 수 있다. 다중상속은 이렇게 사용하면 된다.

 

결과.


Interface1 에서 구현된 일반 메서드 입니다
TempClass 에서 구현된 Interface1의 추상 메서드 입니다
Interface2 에서 구현된 일반 메서드 입니다
TempClass 에서 구현된 Interface2의 추상 메서드 입니다

Process finished with exit code 0


 

댓글목록

등록된 댓글이 없습니다.


개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.