Java MCQs with answers Page - 27

Here, you will find a collection of MCQ questions on Java. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 832.27K Points
Coach

Q. In Java Inheritance

  • (A) all fields of a class are private
  • (B) all fields of a class are protected
  • (C) a new class is derived from an existing class
  • (D) none of these above

A

Admin • 832.27K Points
Coach

Q. What happens in a method if there is an exception thrown in a try block but there is no catch block following the try block?

  • (A) The program ignores the exception.
  • (B) The program will not compile without a complete try/catch structure.
  • (C) The program terminates immediately.
  • (D) The program throws an exception and proceeds to execute the finally block.

A

Admin • 832.27K Points
Coach

Q. The class RuntimeException is the superclass of which of the following classes?

  • (A) NullPointerException
  • (B) NoSuchMethodException
  • (C) IllegalAccessException
  • (D) NoSuchFileException

A

Admin • 832.27K Points
Coach

Q. How many finally blocks can there be in a try/catch structure?

  • (A) There must be 1.
  • (B) There can be 1 following each catch block
  • (C) There can be 0 or 1 following the last catch block.
  • (D) There is no limit to the number of finally blocks following the last catch block.

A

Admin • 832.27K Points
Coach

Q. Which of the following statements is NOT true about creating your own exceptions?

  • (A) Typically, constructors are the only methods that you include when you define your own exception class.
  • (B) The exception class that you define extends either the class Throwable or one of its subclasses.
  • (C) If you have created an exception class, you can define other exception classes extending the definition of the exception class you creat
  • (D) None of the above

A

Admin • 832.27K Points
Coach

Q. What can a method do with a checked exception?

  • (A) Check the exception or ignore it.
  • (B) Return the exception to the sender or handle it in a catch block.
  • (C) Throw the exception to the method that called this method, or handle the exception in a catch block.
  • (D) Handle the exception in the try block or handle the exception in the catch block.

A

Admin • 832.27K Points
Coach

Q. Which of the following is an exception thrown by the methods of the class String?

  • (A) NullPointerException
  • (B) FileNotFoundException
  • (C) NoSuchElementsException
  • (D) NumberFormatException

A

Admin • 832.27K Points
Coach

Q. Which of the following statements is true?

  • (A) The class Exception, which is derived from the class Object, is the superclass of the class Throwable.
  • (B) The class Throwable, which is derived from the class Exception, is the superclass of the class Object.
  • (C) The class Throwable, which is derived from the class Object, is the superclass of the class Exception.
  • (D) None of these

A

Admin • 832.27K Points
Coach

Q. A message string is returned by which method of an Exception object?

  • (A) printMessage()
  • (B) getMessage()
  • (C) printStackTrace()
  • (D) traceMessage()

A

Admin • 832.27K Points
Coach

Q. When is a finally {} block executed?

  • (A) Only when an exception is thrown by a try block
  • (B) Only when there are no exceptions thrown
  • (C) At the end of a program
  • (D) Always after the execution of a try block, regardless of whether or not an exception is thrown