Java Exception Handling (original) (raw)

Which statement about final, finally, and finalize is correct?

Which of the following blocks always executes, regardless of an exception occurring or not?

What will be the output of the following code?

Java `

public class Geeks { public static void main(String[] args) { try { System.out.println("Inside try"); throw new RuntimeException("Error"); } finally { System.out.println("Inside finally"); } } }

`

What will happen in the following code?

Java `

public class Geeks { static void method() throws Exception { throw new Exception("Error occurred"); }

public static void main(String[] args) {
    method();
}

}

`

What is the difference between throw and throws?

What will be the output of the following program?

Java `

class CustomException extends Exception { public CustomException(String message) { super(message); } }

public class Geeks { public static void main(String[] args) { try { throw new CustomException("Custom error occurred"); } catch (CustomException e) { System.out.println(e.getMessage()); } } }

`

What happens when finalize() is called on an object?

What is the output of the following code?

Java `

public class Geeks { public static void main(String[] args) { try { System.exit(0); } finally { System.out.println("Finally executed"); } } }

`

Which of the following is true about custom exceptions?

Which of the following correctly defines a custom exception?

There are 10 questions to complete.

Take a part in the ongoing discussion