Home Tutorial Java Scjp Part2 SCJP Module-2 Question-18

 
 

Share on Google+Share on Google+
SCJP Module-2 Question-18
Posted on: July 8, 2010 at 12:00 AM
Advertisement
The given program below checks your understanding of flow of Java program.

What will be the output of the following code :

class Example18{
static String q = "Hello ";

public static void main(String[] args) {
new Example18().subclass1();
System.out.println(s);
}

void subclass1() {
try {
subclass2();
} catch (Exception e) {
q += "Friends";
}
}

void subclass2() throws Exception {
subclass3();
q += "and";
subclass3();
q += "Brothers";
}

void subclass3() throws Exception {
throw new Exception();
}
}

What will be the output of the code :

1. Hello Friends

2. Hello

3.Friend

4.Compile error

Answer:

(1)

Explanation :

Because 'subclass3' raised exception explicitly due to this, the only execution occurs in the 'catch' block of 'subclass1'.

Advertisement

Related Tags for SCJP Module-2 Question-18:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 8, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com