demo()
메서드를 사용하여 throw 절을 사용할 때 오류가 발생합니다. 상속에서 throw 사용에 대한 제한 사항을 알고 싶습니다.java에서 오버라이드 메소드로 throws 절을 사용하는 중에 오류가 발생 했습니까?
오류는 다음과 같습니다. 예외 ClassNotFoundException
은 Test.demo()
의 throws 절과 호환되지 않습니다. 당신이 방법을 재정의 어떤 그것을 무시 것 방법은 선언하지 않은 것으로 확인 된 예외를 던질 것을 선언 할 수 없습니다 -
Class Test
{
public void demo() throws NumberFormatException, ArrayIndexOutOfBoundsException//error
{
//something here
}
public void demo(String s)
{
//something here
}
}//end of Test class
public class MyTest extends Test
{
public void demo() throws IndexOutOfBoundsException,ClassNotFoundException
{
//something here
}
public static void main(String[] args)
{
}
}
오류 메시지는 무엇입니까? – Thilo
demo() 메서드는 자식 및 부모 클래스에 다른 예외를 던져서는 안됩니다. – TheLostMind
예외 ClassNotFoundException은 Test.demo()의 throws 절과 호환되지 않습니다. – varun