Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to execute finally block after a return statement in a method in Java

1 Answer

0 votes
public class MyClass {
    public static int test() { 
      try {
          System.out.println("return 1");
          return 1;
      } catch(Exception e) {
          System.out.println("return 2");
          return 2;
      } finally {
          System.out.println("Finally will execute even after a return");
      }
    }
    public static void main(String args[]) {
        System.out.println(test());
    }
   
}



/*
run:

return 1
Finally will execute even after a return
1

*/

 



answered Jun 29, 2020 by avibootz

Related questions

1 answer 265 views
265 views asked Dec 11, 2018 by avibootz
1 answer 171 views
1 answer 131 views
1 answer 190 views
4 answers 307 views
1 answer 145 views
...