Given below the sample code :
1 public class SuperClass {
2 static String str = "";
3 public static void main(String[] args) {
4 try {
5 str += "2";
6 throw new Exception();
7 } catch (Exception e) { str += "3";
8 } finally { str += "4"; interrupt(); str += "6";
9 }
10 System.out.println(str);
11 }
12 static void interrupt() { int a = 0; int b = 8/a; }
13 }
How can we correct the above code :
1. No need of correction.
2. By placing the method "interrupt" inside "try" block.
3. By changing the value of variable 'a' to any number except zero.
4. By removing the "interrupt" method from this code.
(2) or (3) or (4)
Error in this code is due to the ' / by zero ' operation of method "interrupt()".
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.