클래스 Product와 인터페이스 LargeProduct가 있습니다. 제품은 LargeProduct를 구현합니다.최종 필드를 할당 할 수 없습니다. 인터페이스의 경우
LargeProduct에는 getter 및 setter 메서드가있는 가변 높이가 있으며 Product 클래스에 구현해야합니다.
LargeProduct의 높이 변수과 같이 정의된다 :
public int getHeight() {
return height;
}
하지만 setter 메소드하지 않습니다 :
public int height = null;
게터 방법은 잘 작동
public void setHeight(int height) {
this.height = height;
}
오류 :
The final field LargeProduct.height cannot be assigned
The static field LargeProduct.height should be accessed in a static way
실제로 제공되는 오류가 확실하지 않습니다. Eclipse를 사용하고 있습니다. 커서를 올려 놓으면 첫 번째 오류가 발생하고 창 하단에는 두 번째 오류가 발생합니다.
인터페이스는 호출자와 수신자 간의 계약을 정의합니다. 메소드와 상수는 필드가 아닌 해당 계약의 일부입니다. (getter 또는 setter가 필요하지 않은 경우) 부모가 필드를 정의하도록하려면 추상 클래스를 사용합니다. –