No student devices needed. Know more
53 questions
When does Exceptions in Java arises in code sequence?
Run Time
Compilation Time
Can Occur Any Time
None of the mentioned
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
Predict the output of following Java program
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Got the Exception 10
Got the Exception 0
Compiler Error
class Test extends Exception { }
class Main {
public static void main(String args[]) {
try {
throw new Test();
}
catch(Test t) {
System.out.println("Got the Test Exception");
}
finally {
System.out.println("Inside finally block ");
}
}
}
Got the Test Exception
Inside finally block
Got the Test Exception
Inside finally block
Compiler Error
Output of following Java program?
class Main {
public static void main(String args[]) {
int x = 0;
int y = 10;
int z = y/x;
}
}
Compiler Error
Compiles and runs fine
Compiles fine but throws ArithmeticException exception
class Test
{
public static void main (String[] args)
{
try
{
int a = 0;
System.out.println ("a = " + a);
int b = 20 / a;
System.out.println ("b = " + b);
}
catch(ArithmeticException e)
{
System.out.println ("Divide by zero error");
}
finally
{
System.out.println ("inside the finally block");
}
}
}
Compile error
Divide by zero error
a = 0
Divide by zero error
inside the finally block
a = 0
inside the finally block
Which of these is a super class of all errors and exceptions in the Java language?
RunTimeExceptions
Throwable
Catchable
None of the above
The built-in base class in Java, which is used to handle all exceptions is
Raise
Exception
Error
Throwable
Which of these keywords must be used to monitor for exceptions?
try
finally
throw
catch
Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
try
finally
throw
catch
Which of these keywords is used to manually throw an exception?
try
finally
throw
catch
What will be the output of the following Java program?
class exception_handling {
public static void main(String args[]) {
try {
System.out.print("Hello" + " " + 1 / 0);
}
catch(ArithmeticException e) { System.out.print("World");
}
}
}
Hello
World
HelloWorld
Hello World
What will be the output of the following Java program?
class exception_handling {
public static void main(String args[]) {
try {
int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
}
catch(ArithmeticException e) { System.out.print("B");
}
}
A
B
Compilation Error
Runtime Error
What will be the output of the following Java program?
class exception_handling {
public static void main(String args[]) {
try {
int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
}
catch(ArithmeticException e) { System.out.print("B");
}
finally {
System.out.print("C");
}
}
}
A
B
AC
BC
What will be the output of the following Java program?
class exception_handling {
public static void main(String args[]) {
try {
int i, sum;
sum = 10;
for (i = -1; i < 3 ;++i)
sum = (sum / i);
}
catch(ArithmeticException e) { System.out.print("0");
}
System.out.print(sum);
}
}
0
05
Compilation Error
Runtime Error
Which of the following classes can catch all exceptions which cannot be caught?
RuntimeException
Error
Exception
ParentException
Which of the following operators is used to generate instance of an exception which can be thrown using throw?
thrown
alloc
malloc
new
Which of the following keyword is used by calling function to handle exception thrown by called function?
throws
throw
try
catch
Which of the following handles the exception when a catch is not used?
finally
throw handler
default handler
java run time system
Which part of code gets executed whether exception is caught or not?
finally
try
catch
throw
Which of the following should be true of the object thrown by a thrown statement?
Should be assignable to String type
Should be assignable to Exception type
Should be assignable to Throwable type
Should be assignable to Error type
At runtime, error is recoverable.
True
False
Which of these class is related to all the exceptions that can be caught by using catch?
Error
Exception
RuntimeExecption
All of the mentioned
Which of these class is related to all the exceptions that cannot be caught?
Error
Exception
RuntimeExecption
All of the mentioned
What exception thrown by parseInt() method?
ArithmeticException
ClassNotFoundException
NullPointerException
NumberFormatException
What will be the output of the following Java code?
class exception_handling {
public static void main(String args[]) {
try {
System.out.print("A");
throw new NullPointerException ("Hello");
}
catch(ArithmeticException e) { System.out.print("B");
}
}
}
A
B
Hello
Runtime Exception
In which of the following package Exception class exist?
java.io
java.net
java.lang
java.util
Which exception is thrown when divide by zero statement executes?
NumberFormatException
NullPointerException
ArithmeticException
None of the listed options
When does Exceptions in Java arises in code sequence?
Run Time
Can Occur Any Time
Compilation Time
None of the mentioned
What is the output of this program?
class Main
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
Finally
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
What will be the output of the following Java code?
public class San {
public static void main(String args[]) {
try {
System.out.print("Hello world ");
}
finally {
System.out.println("Finally executing ");
}
}
}
The program will not compile because no exceptions are specified
The program will not compile because no catch clauses are specified
Hello world
Hello world Finally executing
Which of these clause will be executed even if no exceptions are found?
throws
finally
throw
catch
A single try block must be followed by which of these?
finally
catch
finally & catch
none of the mentioned
Which of these exceptions will occur if we try to access the index of an array beyond its length?
ArithmeticException
ArrayException
ArrayIndexException
ArrayIndexOutOfBoundsException
What will be the output of the following Java code?
class exception_handling {
public static void main(String args[]) {
try {
int a = args.length;
int b = 10 / a;
System.out.print(a);
}
catch (ArithmeticException e) {
System.out.println("1");
}
}
}
Note : Execution command line : $ java exception_handling
0
1
Compilation Error
Runtime Error
What will be the output of the following Java code?
class exception_handling {
public static void main(String args[]) {
try {
throw new NullPointerException ("Hello");
}
catch(ArithmeticException e) { System.out.print("B");
}
}
}
A
B
Compilation Error
Runtime Error
What will be the output of the following Java code?
class exception_handling {
public static void main(String args[]) {
try {
int a = 1;
int b = 10 / a;
try {
if (a == 1)
a = a / a - a;
if (a == 2)
{
int c[] = {1};
c[8] = 9;
}
}
finally {
System.out.print("A");
}
}
catch (Exception e) { System.out.println("B");
}
}
}
A
B
AB
BA
What will be the output of the following Java code?
class exception_handling {
public static void main(String args[]) {
try {
int a = args.length;
int b = 10 / a;
System.out.print(a);
try {
if (a == 1)
a = a / a - a;
if (a == 2)
{
int []c = {1};
c[8] = 9;
}
}
catch (ArrayIndexOutOfBoundException e) {
System.out.println("TypeA");
}
catch (ArithmeticException e) { System.out.println("TypeB");
}
}
}
Note: Execution command line: $ java exception_handling one two
TypeA
TypeB
Compilation Error
Runtime Error
What is the use of try & catch?
It allows us to manually handle the exception
It allows to fix errors
It prevents automatic terminating of the program in cases when an exception occurs
All of the mentioned
Which of these keywords are used for the block to be examined for exceptions?
try
catch
throw
check
Which of these statements is incorrect?
try block need not to be followed by catch block
try block can be followed by finally block instead of catch block
try can be followed by both catch and finally block
try need not to be followed by anything
What will be the output of the following Java code?
class Output {
public static void main(String args[]) {
try {
int a = 0;
int b = 5;
int c = a / b;
System.out.print("Hello");
}
catch(Exception e) { System.out.print("World");
}
}
}
Hello
World
HelloWOrld
Compilation Error
What will be the output of the following Java code?
class Output {
public static void main(String args[]) {
try {
int a = 0;
int b = 5;
int c = b / a;
System.out.print("Hello");
}
}
}
Hello
World
HelloWOrld
Compilation Error
What will be the output of the following Java code?
class Output {
public static void main(String args[]) {
try {
int a = 0;
int b = 5;
int c = a / b;
System.out.print("Hello");
}
finally {
System.out.print("World");
}
}
}
Hello
World
HelloWorld
Compilation Error
What will be the output of the following Java code?
class Output {
public static void main(String args[])
{
try
{
int a = 0;
int b = 5;
int c = b / a;
System.out.print("Hello");
}
catch(Exception e) { System.out.print("World");
}
finally {
System.out.print("World");
}
}
}
Hello
World
HelloWorld
WorldWorld
Which of these methods return description of an exception?
getException()
getMessage()
obtainDescription()
obtainException()
What will be the output of the following Java code?
class Myexception extends Exception
{
int detail;
Myexception(int a) {
detail = a;
}
public String toString() {
return "detail";
}
}
class Output {
static void compute (int a) throws Myexception {
throw new Myexception(a);
}
public static void main(String args[]) {
try {
compute(3);
}
catch(Myexception e) { System.out.print("Exception");
}
}
}
3
Exception
Runtime Error
Compilation Error
What will be the output of the following Java code?
class Myexception extends Exception {
int detail;
Myexception(int a) {
detail = a;
}
public String toString() {
return "detail";
}
}
class Output {
static void compute (int a) throws Myexception
{
throw new Myexception(a);
}
public static void main(String args[]) {
try {
compute(3);
}
catch(DevideByZeroException e) { System.out.print("Exception");
}
}
}
3
Exception
Runtime Error
Compilation Error
What will be the output of the following Java code?
class exception_handling {
public static void main(String args[]) {
try {
throw new NullPointerException ("Hello"); System.out.print("A");
}
catch(ArithmeticException e) { System.out.print("B");
}
}
}
A
B
Compilation Error
Runtime Error
Exception is a class/interface/abstract class/other?
Class
Interface
Abstract class
None of the listed options
Which of these class is highest in hierarchy in java ?
java.lang.Exception
java.lang.Error
java.lang.Throwable
java.lang.Object
Exception and Error are direct subclasses of?
BaseException
Throwable
Object
RuntimeException
https://www.javamadesoeasy.com/2015/10/exception-handling-quiz-in-java.html
a
b
Explore all questions with a free account