I have a simple Java class as shown below:
public class Test {
private String s;
public String foo() {
try {
s = "dev";
return s;
}
finally {
s = "override variable s";
System.out.println("Entry in finally Block");
}
}
public static void main(String[] xyz) {
Test obj = new Test();
System.out.println(obj.foo());
}
}
And the output of this code is this:
Entry in finally Block
dev
Why is s
not overridden in the finally
block, yet control printed output?
There are 2 things noteworthy here: