Knowee
Questions
Features
Study Tools

Select the correct answerWhat is the output of the following program?public class Nptel{ public static void main(String[] args) { try { int a = 5 / 0; } catch (Exception e) { catch (ArithmeticException a) { } } System.out.println("Programming In Java"); }}Options“Programming In Java”Compile time errorArithmeticExceptionRun time error

Question

Select the correct answerWhat is the output of the following program?public class Nptel{ public static void main(String[] args) { try { int a = 5 / 0; } catch (Exception e) { catch (ArithmeticException a) { } } System.out.println("Programming In Java"); }}Options“Programming In Java”Compile time errorArithmeticExceptionRun time error

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is "Compile time error".

The reason is that the catch block inside another catch block is not allowed in Java. The correct way to catch multiple exceptions is to have multiple catch blocks, one after another. So, the nested catch block will cause a compile time error.

Similar Questions

Select the correct answerWhat will be the output of the following Java program? class CT {  public static void main(String args[]) {     try {      int x, y;      y = 0;      x = 5 / y;      System.out.print("A");    }    catch(ArithmeticException e) {  System.out.print("B");        }  } }OptionsBACompilation ErrorRuntime Error

Select the correct answerWhat will be the output of the following Java program? class CT {    public static void main(String args[]) {     try {       System.out.print("Codetantra" + " " + 1 / 0);      }     catch(ArithmeticException e) {    System.out.print("World");          }   } }OptionsCodetantraCodetantraWorldCodetantra WorldWorld

Select the correct answerWhat will be the output of the following Java program? class CT {  public static void main(String args[]) {     try {      int a, sum;      sum = 10;      for (a = -1; a < 3; ++a)        sum = (sum / a);    }    catch(ArithmeticException e) {  System.out.print("0");        }     System.out.print(sum);  } }Options0Compilation ErrorRuntime Error05

Select the correct answerWhat is the output of the following program?public class Nptel extends Thread { public void run() { for (int i = 1; i < 5; i++) { System.out.print(i++ + " "); } } public static void main(String args[]) { Nptel t1 = new Nptel(); t1.run(); }}Options1 2 3 41 3Runtime error1 2

Select the correct answerWhat will be the output of the following Java code?  class Codetantra  {    final public int output(int x, int y) { return 1; }   }   class Program extends Codetantra   {     public int output(int x, int y) { return 2; }   }    public class result   {    public static void main(String args[])     {       Program object = new Program();       System.out.print("y is " + y.output(0, 1));      }   }Optionsy is : 0y is : 1Compilation ErrorAn exception is thrown at runtime

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.