Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 문자열
- oracle
- c++
- 예외처리
- Stack
- Class함수
- 데이터타입
- 예외던지기
- 스레드
- 데이터베이스
- cocos2dx
- 반복문
- Exception
- Thread
- unity
- 상수변수
- 프로그래밍
- cocos2d-x
- db
- interface상속
- c++게임엔진
- 게임엔진
- c#
- 입출력
- cocos2d
- C/C++
- java
- Interface
- singleton
- 동기화블럭
Archives
- Today
- Total
초보 프로그램 개발자
[ 4주차 ] Java - interface 본문
interface
- 추상클래스의 일종
- 일반메소드는 사용하지 못하고 추상메소드만 사용가능
- 변수 선언시 final변수만 선언
- interface를 구현 했을 때 interface가 가지고 있는 모든 메소드를 재정의해야한다.
- interface에서 interface 상속 가능
- 클래스와 다르게 다중 interface 상속 가능
- interface를 상속받을 때 implements 사용 (extends 사용X)
- 데이터 저장소로도 사용된다.
interface Fruit{
String Won = "원"; // public static final이 생략
int getPrice(); // public abstract 가 생략
public String getName();
}
class FruitImpl implements Fruit {
@Override
public int getPrice() {
return 1000;
}
@Override
public String getName() {
return "사과";
}
public String getItem() {
return "과일";
}
}
public class Test7 {
public static void main(String[] args) {
FruitImpl ob = new FruitImpl();
System.out.println(ob.getItem());
System.out.println(ob.getName());
System.out.println(ob.getPrice() + Fruit.Won);
}
}
interface 또한 추상클래스와 마찬가지로 추상메소드를 선언한 뒤 자식클래스에서 재정의를 해주어야 한다.
'교육 일지 > java' 카테고리의 다른 글
[ 4주차 ] Java - 내부클래스 (0) | 2023.05.23 |
---|---|
[ 4주차 ] Java - interface상속 (0) | 2023.05.22 |
[ 4주차 ] Java - 추상클래스(abstract) (0) | 2023.05.22 |
[ 4주차 ] Java - singleton (0) | 2023.05.22 |
[ 3주차 ] Java - Calendar (1) | 2023.05.19 |