MCQ – Java Exceptions

Q) Types of exceptions in Java programming are
  1. Checked exception
  2. unchecked exception
  3. Both A & B
  4. None

Answer: 3


Q) Checked exception caught at
  1. compile time
  2. run time
  3. Both at compile and run time
  4. None

Answer: 1


Q) Unchecked exception caught at
  1. compile time
  2. run time
  3. Both at compile and run time
  4. None

Answer: 2
Unchecked exception caught at run time when we execute the java program. Unchecked java exceptions example are ArithmeticException, null pointer exception etc. let’s say at the run time in the program if a number divide by zero occurs then arithmetic exception happens.


Q) What exception can occur in the below java program if we access 5 element in the array that does not exist?
public class TException {

	public static void main(String[] args) {

		try {

			int a[] = { 5, 10, 15, 20 };
			
			System.out.println("Element :" + a[4]);			
		}
		finally{}

	}

}

  1. ArrayIndexOutOfBoundsException
  2. ArithmeticException
  3. NullPointerException
  4. None

Answer: 1
ArrayIndexOutOfBoundsException unchecked exception will occur at run time when we execute the program.


Q) Which is the super class of all java exceptions classes?
  1. Exception
  2. RuntimeException
  3. Throwable
  4. IOException

Answer: 3


Related Posts