Java

[Java] 추상클래스

데분몽굴 2024. 1. 1. 22:57

추상클래스의 특징

  • 스스로는 인스턴스를 만들 수 없음
  • 자식 클래스로 파생되기 위한 클래스
    • 관련된 여러 클래스들의 공통분모를 정의하기 위한 클래스
public abstract class YalcoGroup {
    protected static final String CREED = "우리의 %S 얄팍하다";

    protected final int no;
    protected final String name;

    public YalcoGroup(int no, String name){
        this.no = no;
        this.name = name;
    }

    public String intro(){
        return "%d호 %s점입니다.".formatted(no, name);
    }
    public abstract void takeOrder ();
}

위 코드는 YalcoGroup이라는 추상클래스이다. 추상클래스는 상속을 통해 구현해야되기 때문에 각 필드들이 protected 지정자로 사용하고 있다.