을 반환 나는 다음과 같은 질문이 있습니다 내가 다음 코드의 출력이자바 마지막으로
try {
int a = 0;
System.out.println("The method will return " + a);
return a;
} catch (Exception e) {
;
}
finally {
System.out.println("Finally executed");
}
이
The method will return 0
Finally executed
내 질문이 될 것이라는 점을 알고있다이다 : 어떤 다음 코드를 반환합니까?
int a = 0;
try {
System.out.println("The method will return " + a);
return a;
} catch (Exception e) {
;
}
finally {
System.out.println("Finally executed");
a = 1;
return a;
}
즉, 마지막으로 메소드가 호출 된 코드 전후에 실행됩니까?
* "내 질문은 다음과 같습니다."* 시도 할 때 어떤 일이 발생 했습니까? –
'finally'는 'try-catch' 시퀀스의 모든 것 다음에 실행되어 필수적인 정리 작업을 수행합니다.따라서 'a'의 값은 결국 1이되고, 예외가 발생하면 0을 반환합니다. –