Why in the below code,the value of x is not updating although the finally block executes,
public class Student
{
public static void main(String...args)
{
ABC obj=new ABC();
System.out.println("x : "+obj.display());
}
}
class ABC
{
int x;
int display()
{
try
{
x=10;
System.out.print("Inside Try ");
return x;
}
finally
{
x=x+20;
System.out.print("I execute ");
}
}
}
The output of this code is
Inside Try I execute x : 10
Although the finally block is executing, the value of x is not changing. Can somebody please explain why?