package main.java.jvm;

/**
 * in test method, x will assign to return value, here should be 1 (it will not throw any errors)
 * then, the finally block will change x to 3, but the return value will not change
 * How finally work is attach the code block in it to try block and catch block
 */
public class TryCatchDemo {

    public int test() {
        int x=0;
        try {
            x=1;
            return x;
        } catch (Exception e) {
            x=2;
            return x;
        } finally {
            x=3;
        }
    }

    public static void main(String[] args) {
        TryCatchDemo tryCatchDemo = new TryCatchDemo();
        System.out.println(tryCatchDemo.test());
    }
}
