인터페이스 (interface)
- 미완성메소드(추상메소드) 와 field 는 final 변수로만 이루어진다.
- 접근제한자는 public 으로만 이루어진다.
protected final double PI = 3.141592; // 오류!! public final double PI = 3.141592; // 가능 O // 인터페이스는 defalut 가 아닌 public 이 생략되어져 있다. double PI = 3.141592; // 가능 O
double area(double x, double y);
// public abstract 가 생략되어져 있다.
public final double PI = 3.141592;
double PI = 3.141592; // public final 이 생략되어져 있다.
-> 인터페이스에서 field 는 기울기 있게 표시된다.
public interface Inter_child extends Inter_father,
Inter_mother{ }
Ex)
public class Rectangle implements Figure{}
인터페이스로 구현된 클래스의 객체는 해당 인터페이스의 타입으로 받을 수 있다.
Ex)
Figure fg1 = new Rectangle();
Figure fg2 = new Triangle();
Figure fg3 = new Circle();
Figure fg4 = new Ellipse();
인터페이스는 객체화 할 수 없다!!
단, 저장소로는 가능하다.
Ex)
Figure fg = new Figure(); // 불가능!!
Figure[] fg_arr = new Figure[4]; // 저장소로는 사용가능
Q . 추상클래스와 인터페이스 중 추상화정도가 높은 것은?
Answer . 인터페이스
-> 인터페이스의 모든 메소드는 추상메소드인데,
추상클래스는 추상메소드가 부분부분이기 때문이다.
my.day16.b.INTERFACE
-> Figure, Rectangle, Triangle, Circle, Ellipse, Main
my.day16.c.INTERFACCE_inheritance
-> Inter_father, Inter_mother, Inter_child, Child, Main