오류노트

[코딩 오류 노트]다형성, 추상 메서드

망고고래 2023. 10. 23. 17:54

1. 부모 클래스에 기본 생성자 미입력

오류 메시지

 

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

Implicit super constructor car2() is undefined. Must explicitly invoke another constructor

 

코드

 

 

해결

부모 클래스에 기본 생성자를 추가한다.

이러한 상황이 생기는 것을 방지하기 위해 기본 생성자를 작성해두는 것이 좋다.

 

 

 

2. 추상 클래스에서 정해놓은 추상 메서드를 오버라이딩하지 않음

오류 메시지

The type pikachu must implement the inherited abstract method pokemon.attack()

The type pikachu must implement the inherited abstract method pokemon.sound()

 

코드

 

해결

추상 클래스의 자식 클래스에서는 반드시 추상 메서드를 오버라이딩한다.

우클릭→source→override/implements methods로 간단히 할 수 있다.