wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

java-ExceptionHandling-vlits

Total questions: 37

Worksheet time: 2hrs 43mins

Name
Class
Date
1.

When does Exceptions in Java arises in code sequence?

a)

Run Time

b)

Compilation Time

c)

Can Occur Any Time

d)

None of the mentioned

2.

Which of these keywords is not a part of exception handling?

a)

try

b)

finally

c)

thrown

d)

catch

3.

Which of these keywords must be used to monitor for exceptions?

a)

try

b)

finally

c)

throw

d)

catch

4.

Which of these keywords must be used to handle the exception thrown by try block in some rational manner?

a)

try

b)

finally

c)

throw

d)

catch

5.

Which of these keywords is used to manually throw an exception?

a)

try

b)

finally

c)

throw

d)

catch

6.

What is the output of the program?

class exception_handling{

public static void main(String args[]){

try{

System.out.print("Hello" + " " + 1 / 0);

}

catch(ArithmeticException e){ System.out.print("World");

}

}

}

a)

Hello

b)

World

c)

HelloWorld

d)

Hello World

7.

What is the output of the following 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)

A

b)

B

c)

Compilation Error

d)

Run Time Error

8.

What is the output of this 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)

A

b)

B

c)

AC

d)

BC

9.

What is the output of the following 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);

}

}

a)

0

b)

05

c)

Compilation Error

d)

Runtime Error

10.

The class at the top of exception class hierarchy is .................

a)

ArithmeticException

b)

Throwable

c)

Object

d)

Exception

11.

In which of the following package Exception class exist?

a)

java.util

b)

java.file

c)

java.io

d)

java.lang

e)

java.net

12.

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

13.

try{

File f = new File("a.txt");

}catch(Exception e){

}catch(IOException io){

}

Is this code create new file name a.txt ?

a)

true

b)

false

c)

Compilation Error

d)

None of these

14.

Which of the below statement is/are true about Error?

A. An Error is a subclass of Throwable.

B. An Error is a subclass of Exception.

C. Error indicates serious problems that a reasonable application should not try to catch.

D. An Error is a subclass of IOException.

a)

A and D

b)

A and B

c)

A and C

d)

B and C

e)

B and D

15.

Given the code. What is the result when this program is executed?

public class Test{

static int x[];

static{

x[0] = 1;

}

public static void main(String args[]){

}

}

a)

ArrayIndexOutOfBoundsException is thrown

b)

ExceptionInInitializerError is thrown

c)

IllegalStateException is thrown

d)

StackOverflowException is thrown

e)

None of these

16.

Which of the following are the most common run-time errors in Java programming.

i) Missing semicolons

ii) Dividing an integer by zero

iii) Converting invalid string to number

iv) Bad reference of objects

a)

i and ii only

b)

ii and iii only

c)

iii and iv only

d)

i and iv only

17.

Which of the following are the most common compile time errors in Java programming.

i) Missing semicolons

ii) Use of undeclared variables

iii) Attempting to use a negative size for an array

iv) Bad reference of objects

a)

i, ii and iii only

b)

ii, iii and iv only

c)

i, ii and iv only

d)

All i, ii, iii and iv

18.

The unexpected situations that may occur during program execution are

i) Running out of memory

ii) Resource allocation errors

iii) Inability to find a file

iv) Problems in network

a)

i, ii and iii only

B)

C)

D)

b)

ii, iii and iv only

c)

i, ii and iv only

d)

All i, ii, iii and iv

19.

……………………….. exception is caused when an applet tries to perform an action not allowed by the browser’s security setting.

a)

Throwable

b)

Restricted

c)

Security

d)

ArrayIndexOutofBounds

20.

State whether the following statements are True or False.

i) A catch can have comma-separated multiple arguments.

ii) Throwing an Exception always causes program termination.

a)

True, False

b)

False, True

c)

True, True

d)

False, False

21.

Which is valid about java.lang.Exceptions?

a)

The class Exception and all its subclasses that are not also subclasses of RuntimeException are checked exceptions.

b)

The class Error and all its subclasses are unchecked exceptions.

c)

The class RuntimeException and all its subclasses are unchecked exceptions.

d)

All.

22.

FileInputStream implements which interface for closing file automatically in java7?

a)

java.lang.AutoClose

b)

java.lang.CloseAutomatically

c)

java.lang.AutoCloseable

d)

java.lang.Closeable

23.

Types of exceptions in Java programming are

a)

Checked exception

b)

unchecked exception

c)

Both A & B

d)

None

24.

Checked exception caught at

a)

compile time

b)

run time

c)

Both at compile and run time

d)

None

25.

Unchecked exception caught at

a)

compile time

b)

run time

c)

Both at compile and run time

d)

None

26.

Direct subclass of Throwable in Java

a)

Exception

b)

Error

c)

Both A & C

d)

None

27.

un-checked(runtime) exception in java is/are

a)

ArrayIndexOutOfBoundsException

b)

ArithmeticException

c)

NullPointerException

d)

All

28.

In below java program, which exception will occur?

public static void main(String[] args) {

FileReader file = new FileReader("test.txt");

}

a)

NullPointerException at compile time

b)

NullPointerException at run time

c)

FileNotFoundException at compiler time

d)

FileNotFoundException at runtime

29.

Incorrect statement(s) about finally block in java exception

a)

Finally block always follow try catch block

b)

finally block always executes whether exception is handled or not.

c)

There can be multiple finally blocks followed by try catch block.

d)

All are correct

30.

True statement(s) about try catch block

a)

It is mandatory to have catch block with every try block

b)

There must be only one catch block followed by try block

c)

There can be multiple catch block followed by try block.

d)

All

31.

True statement about throws and throw is/are

a)

Throws is used with the method signature.

b)

Throw is used within the method.

c)

using throws multiple exceptions can be declared

d)

All are correct.

32.

When the JVM runs out of memory, which exception will be thrown?

a)

MemoryBoundException

b)

OutOfMemoryError

c)

OutOfRangeException

d)

NullReferenceException

33.

When a program is stopped due to lack of memory then -------------------------- is thrown.

a)

OutOfMemoryError

b)

OutOfRangeException

c)

NullReferenceException

d)

MemoryBoundException

34.

Which exception is thrown by read() method ?

a)

Exception

b)

FileNotFoundException

c)

ReadException

d)

IOException

35.

Attempting to access a character that is outside the bounds of a StringBuffer results in a

a)

ArrayIndexOutOfBoundsException

b)

StringOverFlowException

c)

StringException

d)

StringIndexOutOfBoundsException

36.

Exception and Error are immediate subclasses of a class called

a)

Object

b)

Throwable

c)

AWT

d)

Panel

37.

URL throws an exception called

a)

IllegalURLException

b)

URLException

c)

MalformedHostException

d)

MalformedURLException