71. What will be the output of the following Java code?
public class A
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
public class A
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
72. Which of the following classes can catch all exceptions which cannot be caught?
73. What will be the output of the following Java code?
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 (ArrayIndexOutOfBoundException e)
{
System.out.println("TypeA");
}
catch (ArithmeticException e)
{
System.out.println("TypeB");
}
}
}
}
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 (ArrayIndexOutOfBoundException e)
{
System.out.println("TypeA");
}
catch (ArithmeticException e)
{
System.out.println("TypeB");
}
}
}
}
74. What will be the output of the following Java code?
class exception_handling
{
public static void main(String args[])
{
try
{
int i, sum;
sum = 10;
for (i = -1; i < 3 ;++i)
{
sum = (sum / i);
System.out.print(i);
}
}
catch(ArithmeticException e)
{
System.out.print("0");
}
}
}
class exception_handling
{
public static void main(String args[])
{
try
{
int i, sum;
sum = 10;
for (i = -1; i < 3 ;++i)
{
sum = (sum / i);
System.out.print(i);
}
}
catch(ArithmeticException e)
{
System.out.print("0");
}
}
}
75. Which of these keywords are used for the block to be examined for exceptions?
76. Which part of code gets executed whether exception is caught or not?
77. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
78. What will be the output of the following Java code?
class exception_handling
{
public static void main(String args[])
{
try
{
int a = 1;
int b = 10 / a;
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int c[] = {1};
c[8] = 9;
}
}
finally
{
System.out.print("A");
}
}
catch (Exception e)
{
System.out.println("B");
}
}
}
class exception_handling
{
public static void main(String args[])
{
try
{
int a = 1;
int b = 10 / a;
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int c[] = {1};
c[8] = 9;
}
}
finally
{
System.out.print("A");
}
}
catch (Exception e)
{
System.out.println("B");
}
}
}
79. What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
try
{
int a = 0;
int b = 5;
int c = a / b;
System.out.print("Hello");
}
finally
{
System.out.print("World");
}
}
}
class Output
{
public static void main(String args[])
{
try
{
int a = 0;
int b = 5;
int c = a / b;
System.out.print("Hello");
}
finally
{
System.out.print("World");
}
}
}
80. What will be the output of the following Java code?
class exception_handling
{
public static void main(String args[])
{
try
{
throw new NullPointerException ("Hello");
System.out.print("A");
}
catch(ArithmeticException e)
{
System.out.print("B");
}
}
}
class exception_handling
{
public static void main(String args[])
{
try
{
throw new NullPointerException ("Hello");
System.out.print("A");
}
catch(ArithmeticException e)
{
System.out.print("B");
}
}
}
Read More Section(Exceptions)
Each Section contains maximum 100 MCQs question on Exceptions. To get more questions visit other sections.