VOOZH about

URL: https://www.geeksforgeeks.org/quizzes/exception-handling-2-gq/

⇱ Quiz about Java Exception Handling


Last Updated :
Discuss
Comments

Question 1

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

  • final is used to handle exceptions, finally is used for garbage collection, and finalize prevents modification.

  • final makes a variable constant, finally ensures execution of cleanup code, and finalize is called before garbage collection.

  • final is a method, finally is a keyword, and finalize is a block inside try-catch.


  • final, finally, and finalize all serve the same purpose.

Question 2

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

  • try

  • catch

  • finally

  • throw

Question 3

What will be the output of the following code?


  • Inside try

  • Inside try Inside finally

  • Inside try Inside finally RuntimeException

  • Compilation Error

Question 4

What will happen in the following code?


  • Compilation Error

  • Runtime Exception

  • Exception: Error occurred

  • Program runs successfully

Question 5

What is the difference between throw and throws?

  • throw is used to declare exceptions, throws is used to throw exceptions

  • throws is used to declare exceptions, throw is used to throw exceptions

  • Both are used to declare exceptions

  • Both are used to throw exceptions

Question 6

What will be the output of the following program?


  • Custom error occurred

  • Runtime Exception

  • Compilation Error

  • No Output

Question 7

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

  • The object is immediately garbage collected.

  • The garbage collector calls it before collecting the object.

  • The object gets permanently deleted from memory.

  • It prevents an object from being collected.

Question 8

What is the output of the following code?


  • Finally executed

  • No output

  • Runtime Error

  • Compilation Error

Question 9

Which of the following is true about custom exceptions?

  • Custom exceptions cannot extend Exception class

  • Custom exceptions are always checked exceptions

  • Custom exceptions can extend Exception or RuntimeException

  • Custom exceptions do not require a constructor

Question 10

Which of the following correctly defines a custom exception?





There are 10 questions to complete.

Take a part in the ongoing discussion