I have following code :
public class test3
{
public static void main(String a[])
{
System.out.println("In main");
System.out.println(new Demo(0).devide());
}
}
class Demo
{
int x;
Demo(int x)
{
this.x=x;
}
public int devide()
{
try
{
return x/x;
}
catch(Exception e)
{
System.out.println(e);
return 4;
}
finally
{
System.out.println("In finally");
return 1;
}
}
}
In above code I expect 4 as output but output generated is :
In main
java.lang.ArithmeticException: / by zero
In finally
1
so it returns 1