Behaviour of return statement in catch and finally

后端 未结 8 809
情歌与酒
情歌与酒 2020-11-27 11:44

Please see the following code and explain the output behavior.

public class MyFinalTest {

    public int doMethod(){
        try{
            throw new Exce         


        
8条回答
  •  [愿得一人]
    2020-11-27 12:24

    The finally block is always executed (if the matching try was executed) so before the method returns 5 as in the catch block, it executes the finally block and returns 10.

提交回复
热议问题