Exceptions One Mark Questions
Exceptions One Mark Questions
try {
int a = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Error");
}
a) 0
b)Compilation Error
c) Error
d)Runtime Error
try {
int[] a = new int[5];
a[10] = 50;
} catch (Exception e) {
System.out.println("Caught");
}
a) Compilation Error
b) ArrayIndexOutOfBoundsException
c) Runtime Error
d) Caught
Prepared by MUKESH
-2-
3. What will be the output?
try {
String s = null;
System.out.println(s.length());
} catch (NullPointerException e) {
System.out.println("Null error");
}
a) null
b) 0
c) Null error
d) Compilation Error
4. What is printed?
try {
System.out.println("Try");
} finally {
System.out.println("Finally");
}
a) Try Finally
b) Finally
c) Try
d) Compilation Error.
a) Yes
b) No
c) Only in try block
d) Only with throws clause
Prepared by MUKESH
-3-
6. Will this compile?
try {
int x = Integer.parseInt("abc");
} catch (NumberFormatException e) {
System.out.println("Format issue");
}
a) Compilation Error
b) abc
c) Runtime Error
d) Format issue
a) try
b) catch
c) finally
d) none
Prepared by MUKESH
-4-
8. Which block is always executed?
try {
int a = 5 / 0;
} catch (NullPointerException e) {
System.out.println("Null");
} catch (ArithmeticException e) {
System.out.println("Math");
}
a) Null
b) Math
c) Compilation Error
d) 0
9. Is this valid?
catch (Exception e, ArithmeticException ae) {
System.out.println("Invalid");
}
a) Yes
b) Only with Java 8
c) No
d) Only with throws.
a) NullPointerException
b) StringIndexOutOfBoundsException
c) RuntimeException
d) No Exception
Prepared by MUKESH
-5-
11. Which is a checked exception?
a) ArithmeticException
b) ArrayIndexOutOfBoundsException
c) IOException
d) NullPointerException
a) Yes
b) No
c) Only if finally exists
d) With static methods
a) null
b) / by zero
c) Error
d) Compilation Error
Prepared by MUKESH
-6-
14. Is this valid?
try {
} finally {
}
a) Yes
b) No
c) Only with catch
d) Only with throws
a) TimeoutException
b) IOException
c) ArithmeticException
d) InterruptedException
a) Failed
b) Success
c) 5
d) Compilation Error
Prepared by MUKESH
-7-
a) Exception
b) Error
c) Throwable
d) String
a) Yes
b) No
c) Only for IOException
d) Only for FileNotFound
Prepared by MUKESH
-8-
20. What will be the output?
a) 1
b) 2
c) Compilation Error
d) Runtime Exception
a) Throwable
b) Object
c) Exception
d) Runtime
a) Finally
b) Exit
c) Nothing
d) Error
Prepared by MUKESH
-9-
23. What is required with throws?
a) Method body
b) Catch block
c) Static method
d) Declared exception
try {
throw new RuntimeException("Error");
} catch (Exception e) {
System.out.println("Handled");
}
a) Error
b) RuntimeException
c) Handled
d) Nothing
a) Throwable
b) Error
c) Exception
d) Object
Prepared by MUKESH