In this we post we will discuss about one of very important java interview question and question is that What will happen if in a try block we throw an exception but in the finally block we return a int value ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
package com.kkjavatutorials.client; /** * @author KK JavaTutorials * What will the output of this program? */ public class MyTest { public int myMethod() { try { throw new Exception(); } finally { return 10; } } public static void main(String[] args) { MyTest myTest = new MyTest(); int returnedValue = myTest.myMethod(); System.out.println("The return Value : " + returnedValue); } } |
Output of above program:
The return Value : 10
You may also like –
Java program to Remove Duplicate Elements From an Array
Find common elements between two Arrays
Find largest and smallest number in the given Array
Java Program to find duplicate elements in an Array
Count number of words in a string in java
Thanks for visiting blog. If you have any doubts or any suggestions to make please drop a comment.