What will be the output of below code when b = 2 or b = 0.

Here the confusion is finally always execute and method call return; once return statement is used.

package testjava.exceptionhandling;

public class MultipleReturn 
{
	public static void main(String args[])
	{
		int a = 10, b = 0;
		
		System.out.println(multipleReturnTest(10, b));
	}
	
	
	public static int multipleReturnTest(int num1, int num2)
	{
		try
		{
			num1 = num1 / num2;
			return num1;
		}
		catch(Exception e)
		{
			num1 = 7;
			return num1;
		}
		finally
		{
			return num1;
		}
	}	
}

Output

Output = 7; when b = 0; Here catch block return will execute. try and finally block return statement will not execute.

Output = 5, when b = 2; Here try block return will execute. catch and finally block return statement will not execute.