Java Reference
In-Depth Information
11
12 public static void bar() {
13 baz();
14 System.out.println("bar");
15 }
16
17 public static void baz() {
18 System.out.println("baz");
19 }
20 }
You can't tell easily what output this program produces, so let's explore in detail
what the program is doing. Remember that Java always begins with the method
called main . In this program, the main method calls the foo method and the bar
method and then executes a println statement:
public static void main(String[] args) {
foo();
bar();
System.out.println("mumble");
}
Each of these two method calls will expand into more statements. Let's first
expand the calls on the foo and bar methods:
public static void main(String[] args) {
foo();
public static void foo() {
System.out.println("foo");
}
bar();
public static void bar() {
baz();
System.out.println("bar");
}
System.out.println("mumble");
}
This helps to make our picture of the flow of control more complete, but notice
that bar calls the baz method, so we have to expand that as well.
Search WWH ::




Custom Search