How to Use Finally Statement in Java


In this example we will show you how to use the finally statement in Java.

Source Code

package com.beginner.examples;

public class Finally {
  public static void main(String[] args) {
    // use the finally statement
    try {
      System.out.println("1");
    } catch (Exception e) {
      System.out.println("2");
    } finally {
      System.out.println("3");
    }
  }
}

Output:

1
3
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments