Skip to content

Instantly share code, notes, and snippets.

@KhaledLela
Last active October 5, 2016 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KhaledLela/ded9cee046738b5f5c352f783cdd5cc6 to your computer and use it in GitHub Desktop.
Save KhaledLela/ded9cee046738b5f5c352f783cdd5cc6 to your computer and use it in GitHub Desktop.
Try-Finally
public class TryFinallyTest{
private int page;
public static void main(String args[]){
TryFinallyTest instance = new TryFinallyTest();
System.out.print(instance.getPageAndIncrement());
System.out.print(" - ");
System.out.print(instance.getPage());
}
public int getPage(){
return page;
}
private int getPageAndIncrement(){
try{
return page;
}finally{
page++;
}
}
}
@KhaledLela
Copy link
Author

Output:
a. 1 - 1
b. 0 - 1
c. 0 - 0
d. 1 - 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment