SCJP Module-6 Question-21

The sample program code will test your logic in Java programming and help you in better understating of Java program.

 
 

Share on Google+Share on Google+

SCJP Module-6 Question-21

Ads

The sample program code will test your logic in Java programming and help you in better understating of Java program.

Given below the sample code :

class Main {
static String a = "&&";
public static void main(String[] args) {
new Main().a1();
System.out.println(a);
}
void a1() {
try {
a2();
} catch (Exception e) {
a += "x";
}
}
void a2() throws Exception {
a3();
a += "7";
a3();
a += "7x";
}
void a3() throws Exception {
throw new Exception();
}
}

What will be the output of the following code ?

1.Compilation error

2.&&7

3.&&7x

4.-x

Answer

(4)

Advertisements

Posted on: July 15, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles