Java Quiz Day 29

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

What is the difference between checked and unchecked exceptions?


  • Checked exceptions occur at runtime, unchecked exceptions occur at compile time


  • Checked exceptions must be handled or declared, unchecked exceptions don't require handling


  • Unchecked exceptions are caused by hardware failures, checked exceptions are not


  • Unchecked exceptions are always thrown by the JVM, checked exceptions are always user-define

Question 3

Which of the following statements is TRUE about the finally block?

  • It executes only if an exception occurs

  • It executes only if no exception occurs


  • It always executes, even if an exception occurs

  • It executes only if explicitly called

Question 4

What exception is thrown if an invalid index is accessed in an array?

  • NullPointerException

  • IndexOutOfBoundsException

  • ArrayIndexOutOfBoundsException

  • IllegalArgumentException

Question 5

Which keyword is used to declare that a method might throw an exception?

  • throw

  • try

  • throws

  • catch

Question 6

What is the output of the following code?

Java
public class Main {
    public static void main(String[] args) {
        try {
            int result = 10 / 0;
            System.out.println(result);
        } catch (ArithmeticException e) {
            System.out.println("Exception caught");
        } finally {
            System.out.println("Finally block executed");
        }
    }
}


  • Exception caught

  • Finally block executed

  • Exception caught Finally block executed

  • Compilation Error

Question 7

Which block always executes regardless of an exception?

  • try

  • catch

  • finally

  • throw

Tags:

There are 7 questions to complete.

Take a part in the ongoing discussion