What will be the output of the following java code?
public class Test {
public static void main(String[] args) {
int age = -2;
if (age <= 0) {
throw new ArithmeticException();
} else {
System.out.println("Exception occurred");
}
}
}
What will be the output of the following java code?
public class Test {
public static void main(String[] args) {
try {
int i = 1 / 0;
} catch (NumberFormatException e) {
e.printStackTrace();
} finally {
System.out.print(1);
}
System.out.print(2);
}
}
What will be the output of the following java code?
public class Test {
public static void hello() {
try {
throw new Exception();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
System.out.println("Start");
}
}
public static void main(String[] args) {
try {
hello();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("End");
}
}
What will be the output of the following java code?
public class Test {
public static void main(String[] args) {
System.out.print("Java,");
System.out.println(check());
}
static int check() {
try {
int i = 1 / 0;
} finally {
System.out.print("finished,");
return 23;
}
}
}
What will be the output of the following java code?
public class Test {
public static void check() throws Exception {
System.out.print("P,");
throw new RuntimeException();
}
public static void main(String[] args) {
try {
System.out.print("Q,");
check();
} catch (Exception ex) {
System.out.print("R,");
} finally {
System.out.print("S");
}
}
}