Test on Java Exception Handling
Description: Try this test on Exception Handling in java | |
Number of Questions: 15 | |
Created by: Aliensbrain Bot | |
Tags: Exception Handling Programming Java |
Which of the following methods of Iterator class throws NoSuchElementException, if the next element does not exist?
Which of the following exceptions is thrown when one thread has been interrupted by another thread?
Which of the following Exception classes in Java is used to deal with an exception, where an assignment to an array element is of incompatible type?
A programmer has created his own exception for balance in account <1000. The exception is created properly, and the other parts of the programs are correctly defined. Though the program is running but error message has not been displayed. Why did this happen?
Which of the following exceptions is generated when a user tries to create an environment or application in an incorrect state?
Which of the following exception classes is used in Java to deal with a requested method that does not exist in the program?
What will be the output of the program?
try
{
Float f1 = new Float(3.0);
int x = f1.intValue();
byte b = f1.byteValue();
double d = f1.doubleValue();
System.out.println(x + b + d);
}
catch (NumberFormatException e)
{
System.out.println(bad number);
}
Which of the following statements is true?
import java.io.*;
public class MyProgram
{
public static void main(String args[])
{
FileOutputStream out = null;
try
{
out = new FileOutputStream(test.txt);
out.write(122);
}
catch(IOException io)
{
System.out.println(IO Error.);
}
finally
{
out.close();
}
}
}
Given that all methods of class FileOutputStream, including close(), throw an IOException, which of the following is true?
What will be the output of the following program?
class Exc0 extends Exception { }
class Exc1 extends Exc0 { } /* Line 2 */
public class Test
{
public static void main(String args[])
{
try
{
throw new Exc1(); /* Line 9 */
}
catch (Exc0 e0) /* Line 11 */
{
System.out.println(Ex0 caught);
}
catch (Exception e)
{
System.out.println(exception caught);
}
}
}
What will be the output of the program?
public class ExamQuestion6
{
static int x;
boolean catch()
{
x++;
return true;
}
public static void main(String[] args)
{
x=0;
if ((catch() | catch()) || catch())
x++;
System.out.println(x);
}
}
When attempting to compile and run the following code, the result will be
public class MyClass extends Thread{
public MyClass(String s){ msg=s; }
String msg;
public void run(){
System.out.println(msg);
}
public static void main(String[] args) {
new MyClass(Hello);
new MyClass(World);
}
}
What will be the output of the program?
public class X {
public static void main(String[] args) {
try {
badMethod(); /* Line 5 */
System.out.print("A");
} catch (Exception ex) // Line 7
{
System.out.print("B"); // Line 9
} finally // Line 10
{
System.out.print("C"); // Line 12
}
System.out.print("D"); // Line 15
}
public static void badMethod() {
throw new RuntimeException();
}
}
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 18 */
}
}
In the following Java program, it was found that these statements have generated an exception of Array Index out of bound Exception.
int b[ ] = {10,20,30};
b[50] = 100 ;
Choose the correct catch statement for the above code.