abstract class 추상 {
abstract void move();
}
클래스와 유사하게 interface 선언
interface 인터페이스 {
public static final ~~
public abstract 메소드()
}
사용방법은 다음과 같다.
class 클래스이름 implements 인터페이스이름 {
}
모든 멤버 변수는 public static final이다. 생략가능하다.
모든 메소드는 public abstact 이다. 생략가능하다.
extends를 이용해 상속이 가능하다.
클래스와 달리다중상속이 가능하다.
Default Method
(면접질문으로)
StaticMethod
interface에
예시 Generics을 쓸건데, 그타입을 T로 사용할 것이다.
public class GenericContainer<T> {
private T obj;
public T getObj() {
return obj;
}
public T setObj(T obj) {
this.obj = obj;
}
}
GenericContainer<String> gc1 = new GenericContainer<String>();
gc1.setObj("지네릭 컨테이너");
GenericContainer<Integer> gc2 = new GenericContainer<Integer>();
gc2.setObj(123456789);
gc2.setObj(new Integer(4456));