github

Made bySaurav Hathi

MCQ Test Java: Error and Exception Handling

Q1:

What will happen when the following java code is executed?

class Perfectice {

    public static void main(String args[]) {

        Object[] names = new String[3];

        names[0] = new Integer(0);

    }

}

Tags:
Section:
Core Programming
Options:
Q2:

Which of these packages contains the exception Stackoverflow in Java?

Tags:
Section:
Core Programming
Options:
Q3:

Which exception is thrown when java is out of memory?

Tags:
Section:
Core Programming
Options:
Q4:

When does exception in Java arise in code sequence?

Tags:
Section:
Core Programming
Options:
Q5:

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

Tags:
Section:
Core Programming
Options:
Q6:

Which of these keywords is used to handle the exception thrown by try block in java?

Tags:
Section:
Core Programming
Options:
Q7:

What will be the output of this 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");       

}

}

}

Tags:
Section:
Core Programming
Options:
Q8:

What will be the output of this 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");                 

}

}

}

Tags:
Section:
Core Programming
Options:
Q9:

What will be the output of this 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");

}

}

}

Tags:
Section:
Core Programming
Options:
Q10:

What will be the output of this 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);

}

}

Tags:
Section:
Core Programming
Options:
Q11:

Which of the following keywords is used for throwing exception manually in java?

Tags:
Section:
Core Programming
Options:
Q12:

In java, which of these classes is related to all the exceptions that cannot be caught?

Tags:
Section:
Core Programming
Options:
Q13:

Which of the following is the super class of all exception type classes in java?

Tags:
Section:
Core Programming
Options:
Q14:

In java, which of the following handles the exception when catch is not used?

Tags:
Section:
Core Programming
Options:
Q15:

In java, which part of code always gets executed regardless of the fact whether exception is caught or not?

Tags:
Section:
Core Programming
Options:
Q16:

Which of the following exceptions is not thrown by parseInt() method in java?

Tags:
Section:
Core Programming
Options:
Q17:

What will be the output of this java program?

class exception_handling

{

public static void main(String args[])

{

try

{

int a[] = {1, 2,3 , 4, 5};

for (int i = 0; i < 5; ++i)

System.out.print(a[i]);

int x = 1/0;

}

catch(ArrayIndexOutOfBoundsException e)

{

System.out.print("A");                 

}

catch(ArithmeticException e)

{             

System.out.print("B");

}

}

}

Tags:
Section:
Core Programming
Options:
Q18:

What will be the output of this java program?

class exception_handling

{

public static void main(String args[])

{

try

{

int a[] = {1, 2,3 , 4, 5};

for (int i = 0; i < 7; ++i)

System.out.print(a[i]);

}

catch(ArrayIndexOutOfBoundsException e)

{

System.out.print("0");                  

}

}

}

Tags:
Section:
Core Programming
Options:
Q19:

In java, which of these keywords is used by the calling function to guard against the exception that is thrown by called function?

Tags:
Section:
Core Programming
Options:
Q20:

What will be the output of this java program?

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");

}

}

}

Tags:
Section:
Core Programming
Options:
Q21:

Which of these exceptions handles the divide by zero error in java?

Tags:
Section:
Core Programming
Options:
Q22:

What will be the output of this java program?

class exception_handling

{

public static void main(String args[])

{

try

{

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

}

finally

{

System.out.print("World\n");       

}

}

}

Tags:
Section:
Core Programming
Options:
Q23:

What will be the output of this java program?

class San

{

public static void main(String args[])

{

try

{

System.out.print("Hello world ");

}

finally

{

System.out.println("Finally executing ");

}

}

}

Tags:
Section:
Core Programming
Options:
Q24:

What will be the output of this java program?

class exception_handling

{

static void throwexception() throws ArithmeticException

{       

System.out.print("0");

throw new ArithmeticException ("Exception");

}

public static void main(String args[])

{

try

{

throwexception();

}

catch (ArithmeticException e)

{

System.out.println("A");

}

}

}

Tags:
Section:
Core Programming
Options:
Q25:

What will be the output of this java program?

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 (ArrayIndexOutOfBoundsException e)

{

System.out.println("TypeA");

}

catch (ArithmeticException e)

{

System.out.println("TypeB");

}

}

}

}

Tags:
Section:
Core Programming
Options: