wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

22BCA6B-Quiz-Exception Handling

Total questions: 98

Worksheet time: 55mins

Name
Class
Date
1.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

2.

What is the parent class of All Exceptions in JAVA

a)

Throw

b)

Exception

c)

Error

d)

Bug

3.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

4.

try block may or may not contains catch blocks

a)

True

b)

False

5.

What is the purpose of 'throw' keyword

a)

To Raise an exception explicityly

b)

To Raise an exception implicityly

c)

To create user defined exceptions

d)

To create custom exceptions

6.

Which of the following exceptions class belongs to Checked Exception

a)

ArithmeticException

b)

ClassNotFoundExceptions

c)

ClassCastException

d)

ArrayIndexOutOfBoundsException

7.

class IT

{

static public void main(String...args)

{

int k=Integer.parseInt(args[0]);

System.out.println(k);

}

}

if args[0]="gec" then what type of exception is thrown by the above program.

a)

NumberFormatException

b)

NullPointerException

c)

ArrayIndexOutOfBoundsException

d)

InvalidStringException

8.

What are immediate child classes of Throwable

a)

Error

b)

Exception

c)

CheckedException

d)

UnCheckedException

9.

class Add

{

static public void main(String...args)

{

try

{

int a=10,b=0;

System.out.println(a/b);

}

catch(ArithmeticException ex)

{

System.out.println("Error:");

}

}

}

Above program throws an exception at

a)

Runtime

b)

Compile time

c)

either compile time or run time

d)

None of these

10.

What is an exception

a)

Error occurred during the execution of a program

b)

Bug occurred during the compile time of a program

c)

Simply an Error

d)

It is related to input values

11.

How to create our own exception

a)

using 'throw' keyword

b)

using 'throws' keyword

c)

using 'finally' keyword

d)

using 'throwable' keyword

12.

class IT

{

static public void main(String...args)

{

String s=null;

System.out.println("length is:"+s.length());

}

}

a)

It throws NullPointerException

b)

it throws IOException

c)

It throws StringExeption

d)

output is 0

13.

Nested try and Multi-try both are same

a)

It is True

b)

It is False

14.

A java program contains any number of try and catch blocks

a)

True

b)

False

15.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

16.

What is the output of this program?

a)

0

b)

1

c)

2

d)

Compilation Error

17.

What is the output of this program?

a)

2 2

b)

3 3

c)

2 3

d)

3 2

18.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

19.

what is the output?

a)

Base

b)

Derived

c)

compile time error

d)

run-time error

20.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

21.

Which of the following is true about inheritance in Java?

a)

1, 2 and 4

b)

Only 1 and 2

c)

1, 2 and 3

d)

2, 3 and 4

22.

output of the program

a)

Base::show() called

b)

Compiler Error

c)

Derived::show() called

d)

None

23.

output of the program

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

24.

Output of following Java Program?

a)

Derived::show() called

b)

compile time error

c)

Base::show() called

d)

runtime error

25.

Predict the output of following Java program?

a)

0

b)

garbage value

c)

compile time error

d)

runtime error

26.

Predict the output of following Java program

a)

garbage value

b)

0

c)

compile time error

d)

runtime error

27.

output of the program

a)

Compile error

b)

values of obj1:

a = 11 b = 21

values of obj2:

a = 11 b = 21

c)

values of obj1:

a = 11 b = 21

values of obj2:

a = 10 b = 20

d)

values of obj1:

a = 11 b = 20

values of obj2:

a = 10 b = 21

e)

runtime error

28.

Predict the output of the following program.

a)

Compilation error

b)

Inside First

Inside First

c)

Inside First

Inside Second

d)

Runtime error

29.

What is the output of the following JAVA program ?

a)

dogood : dogoodgood

b)

dogood : gooddogood

c)

dogood : dodogood

d)

dogood : dogood

30.

Predict the output?

a)

20

b)

0

c)

Compiler Error

d)

none

31.

Which of the following is/are true about constructors in Java?

a)

1

b)

1,2

c)

1, 2, 4

d)

1,2,3 & 4

32.

output of the program

a)

inside static block

a = 4

inside constructor

a = 11

b)

Compiler Error

c)

Run Time Error

d)

inside static block

a = 4

inside constructor

a = 5

e)

inside static block

a = 10

inside constructor

a = 11

33.

What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?

a)

Method overloading

b)

Method overriding

c)

Method hiding

d)

None of the mentioned

34.

What is the output of this program?

a)

2

b)

3

c)

7

d)

compile time error

35.

what is the output

a)

9.0 9.0

b)

9 9

c)

compile time error

d)

none

36.
a)

I am a Person

b)

I am a Student

c)

I am a Person I am a Student

d)

I am a Student I am a Person

37.

Determine the output?

a)

r1 r4 pre b1 b2 post

b)

pre r1 r4 b1 b2 r2 r3 post

c)

r1 r4 pre b1 b2 r3 r2 post

d)

r1 r4 pre b1 b2 post r3 r2

38.

Determine the output?

a)

one

b)

one two

c)

one two 20

d)

20

e)

one 20

39.

Read the statement

a)

Declare the method with the keyword public.

b)

Declare the method with the keyword private.

c)

Declare the method with the keyword protected.

d)

Do not declare the method with any accessibility modifiers.

e)

Declare the method with the keyword public and private.

40.

Read the statement

a)

Only (III)

b)

(II) and (III)

c)

(I) and (II)

d)

Only (I)

e)

(I), (II) and (III)

41.

Read the Program

a)

1 and 2

b)

2 and 4

c)

3 and 4

d)

1 and 3

42.

A Package is the collection of

a)

classes

b)

interfaces

c)

classes and interfaces

d)

editing tools

e)

editing tools and interfaces

43.

which of these lines will give compile time error?

a)

1

b)

2

c)

3

d)

4

e)

None of these

44.

The class at the top of the exception hierarchy is

a)

ArithmeticException

b)

Throwable

c)

Object

d)

Exception

45.

in which package Exception class is available?

a)

java.util

b)

java.file

c)

java.io

d)

java.lang

e)

java.net

46.

Exception generated in try block will caught in...... block

a)

catch

b)

throw

c)

throws

d)

finally

47.

which keyword is used to explicitly throw an exception?

a)

try

b)

throwing

c)

catch

d)

throw

e)

throws

48.

which exception will through by decided by zero?

a)

NumberFormatException

b)

ArithmeticException

c)

NullPointerException

d)

None of these

49.

What happen in case of multiple catch blocks

a)

Either super or subclass can be caught first.

b)

The superclass exception must be caught first.

c)

The superclass exception cannot caught first.

d)

None of these

50.

What will be the output?

a)

inCatchBlock

b)

inCatchBlock inFinallyBlock

c)

inFinallyBlock

d)

The program will return without printing anything

51.

Given the following piece of code

a)

1 and 4

b)

2 and 3

c)

2 and 4

d)

3 and 4

e)

1 and 2

52.

what is the output?

a)

There is a NullPointerException.

b)

There is a NullPointerException. Everything went fine.

c)

There is a NullPointerException. There is an Exception.

d)

This code will not compile, because in Java there are no pointers.

53.

what is the output?

a)

One

b)

Two

c)

One Two

d)

Compilation Error

54.

Read the statement

a)

A and D

b)

A and B

c)

A and C

d)

B and C

55.

What is the output?

a)

"doCdoBdoA" is printed

b)

"doAdoBdoC" is printed

c)

"doBdoAerror" is printed

d)

"error" is printed

e)

nothing is printed

56.

what will be the result if NullPointerException occurs at line 2.

a)

1

b)

3

c)

2 3

d)

1 3

e)

1 2 3

57.

What is the output?

a)

"one" is printed.

b)

"null pointer exception" is printed.

c)

"exception" is printed.

d)

Compilation fails saying NullPointerException has already been caught.

e)

None of these

58.

what is the output after compilation of this code?

a)

Overridden: hello (String, Integer[])

b)

Compilation fails

c)

hello (String, Integer[])

d)

None of these

59.

Is this program create a new file with a.txt

a)

true

b)

false

c)

None of these

d)

Compilation Error

60.

what is the output?

a)

Value-A

b)

Compilation fails-Exception NullPointerException is not compatible with throws clause in A.printName()

c)

Name-B

d)

Compilation succeed but no output

e)

None of these

61.

What is the output of this program?

a)

Prints out: Exception

b)

Prints out: Exception Finally

c)

Compile with error

d)

Prints out: Finally

e)

None of these

62.

What is the output?

a)

3

b)

3.5

c)

Compilation Error

d)

None of these

63.

what exception could be handled by catch block

a)

IllegalStateException

b)

ClassCastException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

e)

None of these

64.

What is the output?

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

none of the above

65.

What is the output?

a)

Got the Test Exception

Inside finally block

b)

Got the Test Exception

c)

Inside finally block

d)

Compiler Error

66.

What is the output?

a)

Caught base class exception

b)

Caught derived class exception

c)

Compiler Error because derived is not throwable

d)

Compiler Error because base class exception is caught before derived class

67.

What is the output?

a)

Compile error

b)

Divide by zero error

c)

a = 0

Divide by zero error

inside the finally block

d)

a = 0

e)

inside the finally block

68.

What is the output?

a)

error occurred

End of the program

b)

Not Eligible for voting

End of the program

c)

Eligible for voting

End of the program

d)

none

69.

What is the purpose of a try-catch block in Java?

a)

To improve code readability.

b)

To optimize performance of the program.

c)

To define variables in a method.

d)

To handle exceptions and prevent program crashes.

70.

How do you throw an exception in Java?

a)

Use 'throw new Error("message");' instead of Exception.

b)

Throw an exception using 'throw Exception();' with no message.

c)

Use 'throw new Exception("message");' to throw an exception in Java.

d)

Use 'throw Exception("message");' without 'new'.

71.

What is the difference between checked and unchecked exceptions?

a)

Checked exceptions are always runtime errors.

b)

Checked exceptions require handling, while unchecked exceptions do not.

c)

Both checked and unchecked exceptions require handling.

d)

Unchecked exceptions must be declared in the method signature.

72.

When is the finally block executed in Java?

a)

The finally block is executed after the try and catch blocks, regardless of exceptions.

b)

The finally block is executed before the try block.

c)

The finally block is executed only if an exception occurs.

d)

The finally block is executed only if there is no catch block.

73.

Can you nest try-catch blocks in Java?

a)

No, try-catch blocks cannot be nested in Java.

b)

Yes, you can nest try-catch blocks in Java.

c)

You can only have one try block in Java.

d)

Catch blocks must always follow a try block directly without nesting.

74.

What happens if an exception is not caught?

a)

The program will run faster.

b)

The program may terminate unexpectedly.

c)

The exception will be logged automatically.

d)

The program will continue to run without issues.

75.

What is the syntax for a try-catch block?

a)

try { /* code */ } catch { /* handle error */ }

b)

try { /* code */ } catch (ExceptionType e) { /* handle exception */ }

c)

try { /* code */ } finally { /* cleanup */ }

d)

try (/* code */) { /* handle exception */ }

76.

How do you create a custom exception in Java?

a)

public class MyCustomException extends Exception { public MyCustomException(String message) { super(message); } public MyCustomException(String message, Throwable cause) { super(message, cause); }}

b)

public class MyCustomException extends RuntimeException { }

c)

public class MyCustomException { public MyCustomException() { } }

d)

public class MyCustomException implements Exception { }

77.

What is the role of the throw keyword?

a)

The throw keyword is used to define a function.

b)

The throw keyword is used to raise an exception.

c)

The throw keyword is used to catch exceptions.

d)

The throw keyword is used to declare variables.

78.

What are some common checked exceptions in Java?

a)

NullPointerException

b)

ArrayIndexOutOfBoundsException

c)

IllegalArgumentException

d)

IOException, SQLException, ClassNotFoundException

79.

What are some examples of unchecked exceptions?

a)

IOException

b)

SQLException

c)

FileNotFoundException

d)

Examples of unchecked exceptions include NullPointerException, ArrayIndexOutOfBoundsException, ClassCastException, and IllegalArgumentException.

80.

How can you handle multiple exceptions in a single catch block?

a)

Ignore exceptions and let them propagate up the call stack.

b)

Use a single catch block with multiple exception types separated by a pipe (|).

c)

Only catch the most specific exception type.

d)

Use multiple catch blocks for each exception type.

81.

What is the significance of the finally block?

a)

The 'finally' block can be used to declare variables in a method.

b)

The 'finally' block is only executed if no exceptions occur.

c)

The 'finally' block is used to define a method in a class.

d)

The 'finally' block ensures that specific code runs after try/catch, regardless of exceptions.

82.

Can you have a try block without a catch block?

a)

Yes, a try block can exist without any additional blocks.

b)

No, a try block is invalid without a catch or finally block.

c)

Yes, you can have a try block without a catch block if a finally block is present.

d)

No, a try block must always have a catch block.

83.

What is the difference between throw and throws in Java?

a)

'throw' is used for declaring exceptions in method signatures, 'throws' is for throwing exceptions.

b)

'throw' is for throwing exceptions, 'throws' is for declaring exceptions in method signatures.

c)

'throw' can only be used in static methods, while 'throws' can be used anywhere.

d)

'throw' is a keyword for handling errors, 'throws' is for logging exceptions.

84.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

85.

What is the parent class of All Exceptions in JAVA

a)

Throw

b)

Exception

c)

Error

d)

Bug

86.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

87.

What is the purpose of 'throw' keyword

a)

To Raise an exception explicityly

b)

To Raise an exception implicityly

c)

To create user defined exceptions

d)

To create custom exceptions

88.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

89.

How to create our own exception

a)

using 'throw' keyword

b)

using 'throws' keyword

c)

using 'finally' keyword

d)

using 'throwable' keyword

90.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException

91.

What will it print?

a)

1

2

3

30

b)

1

2

30

c)

1

2

3

11

d)

1

2

11

92.

What will this program print?

a)

Nothing, there is an error

b)

There was a ValueError, please try again

c)

num1num2num1^{num2}

d)

num2num1num2^{num1}

93.

public class Foo

{

public static void main(String[] args)

{

try

{

return;

}

finally

{

System.out.println( "Finally" );

}

}

}

a)

Finally

b)

Compilation fails.

c)

The code runs with no output

d)

An exception is thrown at runtime.

94.

class Main {

public static void main(String args[]) {

try {

throw 10;

}

catch(int e) {

System.out.println("Got the Exception " + e);

}

}

}

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

none

95.

Choose the CORRECT mechanism of exception handling.

a)

try block --> catch block --> finally block

b)

try block --> catch block --> throws exception

c)

try block --> catch block --> finally --> throws exception

d)

try block --> throws exception--> catch block --> finally block

96.

What is the output?

a)

The code will lead to a compilation error as declaration of the display method has been provided in two interface.

b)

The code will lead to a compilation error due to public modifier while declaring the display method.

c)

The code will compile and execute successfully showing the output Welcome to Examveda.

d)

The code will lead to a compilation error as the display method is not declared as abstract.

e)

None of these

97.

Exception is a class/interface/abstract class/other?

a)

Class

b)

Interface

c)

Abstract class

d)

Other

98.

1. class main_class

2. {

3. public static void main(String args[])

4. {

5. int y = 10;

6. if (y == 10)

7. {

8. int y = 11;

9. System.out.println(y);

10. }

11. }

12. }

a)

Compilation error

b)

10

c)

11

d)

Run time error