Last active
October 5, 2016 08:50
-
-
Save KhaledLela/ded9cee046738b5f5c352f783cdd5cc6 to your computer and use it in GitHub Desktop.
Try-Finally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
a. 1 - 1
b. 0 - 1
c. 0 - 0
d. 1 - 0