try-catch-finally return statement in

If there is a return statement in the finally block, it will overwrite the other functions return statement.

public class Demo{
  public static void main(String args[]){
    int num = 10;
   System.out.println(test(num));
}
public static int test( int b){
    try
   {
    b += 10;
     return b;
   }
    catch (RuntimeException e)
   {
   }
    catch (Exception e2)
   {
   }
   finally
   {
    b += 10;
     return b;
   }
  }
}
 
Return 30

Guess you like

Origin www.cnblogs.com/67373cyf/p/11264492.html