추상클래스
- 추상클래스를 확장한 새로운 추상클래스를 만들 수 있다.
abstract class AbstactAlgorithm {
abstract void steps();
}
abstract class Algorithm1 extends AbstractAlgorithm {}
- 추상클래스도 멤버변수와 구현된 메서드를 가질 수 있다.
abstract class AbstractAlgorithm {
private int stepCount;
public int getStepCount() {
return stepCount;
}
}
인터페이스
- default 키워드를 통해 인터페이스의 기본 메서드를 구현 할 수 있다.
- 상수를 가질 수 잇다.
interface ExampleInterface {
int constant = 5;
default void print() {
System.out.println("default");
}
}
interface vs abstract class
- 인터페이스안의 모든것은 개방되어야함 (public)
- 추상클래스는 private 하게 내용물을 담을 수 있음
- 클래스는 여러 인터페이스를 구현할 수 있음
- 클래스는 여러 추상클래스를 확장할 수 없음