What will be the output of the following 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 (ArrayIndexOutOfBoundException e)
{
System.out.println(“TypeA”);
}
catch (ArithmeticException e)
{
System.out.println(“TypeB”);
}
}
}
a) TypeA
b) TypeB
c) 0TypeA
d) 0TypeB
Answer: d
Explanation: Execution command line is “$ java exception_ handling one two” hence there are two input making args.length = 2, hence “c[8] = 9” in second try block is executing which throws ArrayIndexOutOfBoundException which is caught by catch of nested try block. Hence 0TypeB is printed.
Output:
0TypeB
Related Posts
The __________ standard is an alternative for single sign-on across organizations, and has seen increasing acceptance in recent years.
The ___________________ is a standard for exchanging authentication and authorization information between different security domains, to provide cross-organization single sign-on.
A single ______________ further allows the user to be authenticated once, and multiple applications can then verify the user’s identity through an authentication service without requiring reauthentication.
Even with two-factor authentication, users may still be vulnerable to_____________attacks.
Many applications use _________________ where two independent factors are used to identify a user.
_________ is an attack which forces an end user to execute unwanted actions on a web application in which he/she is currently authenticated.
A Web site that allows users to enter text, such as a comment or a name, and then stores it and later display it to other users, is potentially vulnerable to a kind of attack called a ___________________ attack.
Join The Discussion