Could you please explain me how these answers was received and why they are corr
ID: 3553449 • Letter: C
Question
Could you please explain me how these answers was received and why they are correct? Thank you!
QUESTION 1
Give the output of each of the Java application shown below. Assume that when "methC" is called it throws the exception indicated in the comment next to the call to methC. Give the output generated by the code shown below:
public class QuesX3
{
public static void main (String [] args)
{
QuesX3 x = new QuesX3();
x.methA();
}
public void methA()
{
try
{
System.out.println("One");
methC(); // throws KeyAlreadyExistsException
System.out.println("Three");
System.out.println("Four");
}
catch ( KeyAlreadyExistsException e)
{
System.out.println("Five");
}
}
public void methC()
{
if (Math.random() >= 0.001)
throw new KeyAlreadyExistsException();
}
}
Question options:
1)
One
2)
One
Five
3)
One
Five
Three
Four
4)
One
Three
Four
Five
5)
<i>No output is generated</i>
6)
One
Exception in thread "main" KeyAlreadyExistsException
at QuesX3.methC(QuesX3.java:29)
at QuesX3.methA(QuesX3.java:16)
at QuesX3.main(QuesX3.java:8)
Question 2
Give the output of each of the Java application shown below. Assume that when "methC" is called it throws the exception indicated in the comment next to the call to methC. Give the output generated by the code shown below:
public class QuesX3
{
public static void main (String [] args)
{
QuesX3 x = new QuesX3();
x.methA();
}
public void methA()
{
try
{
System.out.println("One");
methC(); // throws KeyAlreadyExistsException
System.out.println("Three");
System.out.println("Four");
}
catch ( Exception e)
{
System.out.println("Five");
}
}
public void methC()
{
if (Math.random() >= 0.001)
throw new KeyAlreadyExistsException();
}
}
Question options:
1)
One
2)
One
Five
3)
One
Five
Three
Four
4)
One
Three
Four
Five
5)
<i>No output is generated</i>
6)
One
Exception in thread "main" KeyAlreadyExistsException
at QuesX3.methC(QuesX3.java:29)
at QuesX3.methA(QuesX3.java:16)
at QuesX3.main(QuesX3.java:8)
Question 3
Give the output of each of the Java application shown below. Assume that when "methC" is called it throws the exception indicated in the comment next to the call to methC. Give the output generated by the code shown below:
public class QuesX3
{
public static void main (String [] args)
{
QuesX3 x = new QuesX3();
x.methA();
}
public void methA()
{
try
{
System.out.println("One");
methC(); // throws KeyAlreadyExistsException
System.out.println("Three");
System.out.println("Four");
}
catch ( IndexOutOfBoundsException e)
{
System.out.println("Five");
}
}
public void methC()
{
if (Math.random() >= 0.001)
throw new KeyAlreadyExistsException();
}
}
Question options:
1)
One
2)
One
Five
3)
One
Five
Three
Four
4)
One
Three
Four
Five
5)
<i>No output is generated</i>
6)
One
Exception in thread "main" KeyAlreadyExistsException
at QuesX3.methC(QuesX3.java:29)
at QuesX3.methA(QuesX3.java:16)
at QuesX3.main(QuesX3.java:8)
Question 4
Give the output of each of the Java application shown below. Assume that when "methC" is called it throws the exception indicated in the comment next to the call to methC. Give the output generated by the code shown below:
import javax.management.openmbean.*;
public class QuesX3
{
public static void main (String [] args)
{
QuesX3 x = new QuesX3();
try
{
x.methA();
}
catch (Exception e)
{
System.out.println("Six");
}
}
public void methA()
{
try
{
System.out.println("One");
methC(); // throws KeyAlreadyExistsException
System.out.println("Three");
}
catch ( IndexOutOfBoundsException e)
{
System.out.println("Four");
}
finally
{
System.out.println("Five");
}
}
public void methC()
{
if (Math.random() >= 0.001)
throw new KeyAlreadyExistsException();
}
}
Question options:
1)
One
2)
One
Five
3)
One
Four
Five
4)
One
Three
Four
Five
5)
One
Four
Five
Six
6)
One
Three
Four
Five
7)
One
Three
Four
Five
Six
8)
One
Five
Six
9)
One
Five
Three
Four
10)
<i>No output is generated</i>
11)
One
Exception in thread "main" KeyAlreadyExistsException
at QuesX3.methC(QuesX3.java:29)
at QuesX3.methA(QuesX3.java:16)
at QuesX3.main(QuesX3.java:8)
Question 5
Indicate whether or not the code below will compile (in this question you are looking for compilation errors related to exception handling):
import java.rmi.*;
class Xyz3
{
public static void main (String [] args)
{
methA();
}
public static void methA()
{
double x = Math.random() * 10; // random # from 0 - 9
try
{
if (x > 5.0)
throw new MarshalException("Error!");
}
catch (Exception e)
{
}
}
}
Question options:
1)
Yes, it will compile.
2)
No, it will not compile.
Question 6
Indicate whether or not the code below will compile (in this question you are looking for compilation errors related to exception handling):
import java.rmi.*;
class Xyz3
{
public static void main (String [] args)
{
methA();
}
public static void methA()
{
double x = Math.random() * 10; // random # from 0 - 9
if (x > 5.0)
throw new MarshalException("Error!");
}
}
Question options:
1)
Yes, it will compile.
2)
No, it will not compile.
Question 7
Indicate whether or not the code below will compile (in this question you are looking for compilation errors related to exception handling):
import java.rmi.*;
class Xyz3
{
public static void main (String [] args)
{
methA();
}
public static void methA() throws MarshalException
{
double x = Math.random() * 10; // random # from 0 - 9
if (x > 5.0)
throw new MarshalException("Error!");
}
}
Question options:
1)
Yes, it will compile.
2)
No, it will not compile.
Question 8
Indicate whether or not the code below will compile (in this question you are looking for compilation errors related to exception handling):
import java.rmi.*;
class Xyz3
{
public static void main (String [] args) throws MarshalException
{
methA();
}
public static void methA() throws MarshalException
{
double x = Math.random() * 10; // random # from 0 - 9
if (x > 5.0)
throw new MarshalException("Error!");
}
}
Question options:
1)
Yes, it will compile.
2)
No, it will not compile.
Question 9
Indicate whether or not the code below will compile (in this question you are looking for compilation errors related to exception handling):
import java.rmi.*;
class Xyz3
{
public static void main (String [] args)
{
try
{
methA();
}
catch (Exception e)
{
}
}
public static void methA() throws MarshalException
{
double x = Math.random() * 10; // random # from 0 - 9
if (x > 5.0)
throw new MarshalException("Error!");
}
}
Question options:
1)
Yes, it will compile.
2)
No, it will not compile.
Question 10
Indicate whether or not the code below will compile (in this question you are looking for compilation errors related to exception handling):
class Xyz3
{
public static void main (String [] args)
{
methA();
}
public static void methA()
{
double x = Math.random() * 10; // random # from 0 - 9
if (x > 5.0)
throw new IndexOutOfBoundsException();
}
}
Question options:
1)
Yes, it will compile.
2)
No, it will not compile.
Bottom of Form
Close
1)
One
2)
One
Five
3)
One
Five
Three
Four
4)
One
Three
Four
Five
5)
<i>No output is generated</i>
6)
One
Exception in thread "main" KeyAlreadyExistsException
at QuesX3.methC(QuesX3.java:29)
at QuesX3.methA(QuesX3.java:16)
at QuesX3.main(QuesX3.java:8)
Question 2
Explanation / Answer
1) 2
2) 2
3) 6
4) 8 finally always get executed
5) 1
6) 2 exception is not handled
7) 2
8) 1
9) 2
10)1