Behaviour of return statement in catch and finally

后端 未结 8 851
情歌与酒
情歌与酒 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:21

    finally block will always execute (only exception is it encounters System.exit() anywhere before it), so simply the 5 is replaced (overridden) by 10 before returning by finally block

提交回复
热议问题