10/14 인터페이스

Bam·2022년 10월 14일
0

자바

목록 보기
4/19
추상 메서드의 집합(프로그래밍 관점)
구현된 것이 전혀 없는 설계도, 껍데기

메서드를 통해서 접근해야함 - 캡슐화(iv를 보호)

추상클래스와 인터페이스의 차이
추상메서드를 가지고있는 일반클래스
추상메서드만 가지고있는 집합

interface 인터페이스 이름 {
 public static final 타입 상수이름 = 값;  <- 상수
 public abstract 메서드이름(매개변수); <- 추상메서드
}

*다중 상속
interface Fightable extends Movable , Attackable { }
interface Movealbe {
		void move(int x, int y);
}
interface Attackable {
		void attack(Unit u);
}

*상속
1. extends 추상클래스
미완성클래스를 완성시키는 것
(추상메서드를 완성)
class AudioPlayer extends Player {
	void play(int pos) { }
    void stop() { }
 }
 
2. implements 인터페이스이름
추상메서드를 완성하는 것 <- 구현
class Fighter implements Fightable {
	public void move(int x, int y) { }
    public void attack(Unit u) { }
 }
 
 interface Fightable {
 	void move(int x, int y);
    void attack(Unit u);
  }
profile
Challenger

0개의 댓글