Java Reference
In-Depth Information
Section 1.4: Procedural Decomposition
19.
What is the output of the following program? (You may wish to draw a structure diagram first.)
1
public class
Tricky {
2
public static void
main(String[] args) {
3 message1();
4 message2();
5 System.out.println("Done with main.");
6 }
7
8
public static void
message1() {
9 System.out.println("This is message1.");
10 }
11
12
public static void
message2() {
13 System.out.println("This is message2.");
14 message1();
15 System.out.println("Done with message2.");
16 }
17 }
20.
What is the output of the following program? (You may wish to draw a structure diagram first.)
1
public class
Strange {
2
public static void
first() {
3 System.out.println("Inside first method");
4 }
5
6
public static
void second() {
7 System.out.println("Inside second method");
8 first();
9 }
10
11
public static void
third() {
12 System.out.println("Inside third method");
13 first();
14 second();
15 }
16
17
public static void
main(String[] args) {
18 first();
19 third();
20 second();
21 third();
22 }
23 }
Search WWH ::
Custom Search