rect answerWhat will be the output of the following Java code? class Codetantra { public static void main(String args[]) { try { System.out.print("Good" + " " + 1 / 0); } finally { System.out.print("Morning"); } } }
Question
rect answerWhat will be the output of the following Java code? class Codetantra { public static void main(String args[]) { try { System.out.print("Good" + " " + 1 / 0); } finally { System.out.print("Morning"); } } }
Solution
The code will throw an ArithmeticException because you are trying to divide by zero. However, because this is in a try block with a finally clause, "Morning" will still be printed out. So, the output will be an exception message followed by "Morning".
Similar Questions
Select the correct answerWhat will be the output of the following Java code? class Codetantra { public static void main(String args[]) { try { System.out.print("Good" + " " + 1 / 0); } finally { System.out.print("Morning"); } } }OptionsMorningGoodCompilation ErrorFirst "Morning" then "Exception"
rrect answerWhat will be the output of the following Java code? class Name { public static void main(String args[]) { try { int ct1 = 0; int ct2 = 5; int ct3 = ct2 / ct1; System.out.print("Hello"); } catch(Exception e) { System.out.print("CodeTantra"); } } }
rect answerWhat will be the output of the following Java program?class conditional_statements { public static void main(String args[]) { final int u=10,v=20; while(u<v) { System.out.println("Good"); } System.out.println("Morning"); } }
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 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
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.