AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 1 - 10 of 10 questions

1

The exception class is in ____ package

a

java.file

b

java.io

c

java.lang

d

java.util

correct answer c
2

Which keyword is used to monitor statement for exception?

a

try

b

catch

c

throw

d

throws

correct answer a
3

If an exception is generated in try block , then it is caught in ____ block

a

finally

b

throw

c

catch

d

throws

correct answer c
4

______ is a superclass of all exception classes.

a

Exception

b

throwable

c

RuntimeException

d

IOException

correct answer b
5

In case of multiple catch blocks,______

a

The superclass exception must be caught first

b

The superclass exception can't be caught first

c

Either super or subclass can be caught first

d

None of these

correct answer b
6

Which method is used to print the description of the exception?

a

printStackTrace()

b

printExceptionMessage()

c

printStackMessage()

d

printExceptionTrace()

correct answer a
7

What is the output of following try catch block try

{
int i;
return;
}
catch(Exception e)
{
System.out.println('Hello India”);
}
finally
{
System.out.println('Hello Morbi”);
}
a

Hello India

b

Hello India Hello Morbi

c

Hello Morbi

d

the program will return without printing anything

correct answer c
8

What will be the output of the program? 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.

correct answer a
9

What will be the output of the program? public class Test { public static void aMethod() throws Exception { try /* Line 5 */ { throw new Exception(); /* Line 7 */ } finally /* Line 9 */ { System.out.print("finally "); /* Line 11 */ } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) /* Line 20 */ { System.out.print("exception "); } System.out.print("finished"); /* Line 24 */ } }

a

Finally

b

Compilation fails.

c

exception finished

d

finally exception finished

correct answer d
10

What will be the output of the program? public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (Exception ex) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } public static void badMethod() { throw new Error(); /* Line 22 */ } }

a

ABCD

b

Compilation fails.

c

C is printed before exiting with an error message

d

BC is printed before exiting with an error message

correct answer c
Select a company to compare with

vs

Similar Companies