Question 14
public class MyProgram {
public static void throwit() {
throw new RuntimeException();
}
public static void main (
String args[]){
try {
System.out.println("Hello world ");
throwit();
System.out.println("Done with try block");
}
finally{
System.out.println("Finally executing");
}
}
}
answer is "the program will print Hello world, then will print Finally executing, then will print that a RuntimeException had occurred.
Question 15
public class RTExcept {
public static void throwit() {
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args) {
try {
System.out.print("hello ");
throwit();
}
catch (Exception re) {
System.out.print("caught ");
}
finally{
System.out.print("finally ");
}
System.out.println("after ");
}
}
answer is hello throwit caught finally after