Java Reference
In-Depth Information
Notice that they are listed in random order and that their methods' behavior is more
complicated than the previous example:
1 public class E extends F {
2 public void method2() {
3 System.out.print("E 2 ");
4 method1();
5 }
6 }
1 public class F extends G {
2
public String toString() {
3
return "F";
5 }
6
7 public void method2() {
8 System.out.print("F 2 ");
9
super .method2();
10 }
11 }
1 public class G {
2
public String toString() {
3
return "G";
5 }
6
7 public void method1() {
8 System.out.print("G 1 ");
9 }
10
11 public void method2() {
12 System.out.print("G 2 ");
13 }
14 }
1 public class H extends E {
2 public void method1() {
3 System.out.print("H 1 ");
5 }
6 }
In order to determine the best order in which to examine the classes, you could
draw a diagram like the one in Figure 9.2. Then make a table and fill in each class's
behavior from top to bottom in the hierarchy. First identify the top class in the hierarchy.
Look for the one whose header has no extends clause. In this example, that is the G
class. Its methods have simple behavior, so we can fill in that row of the table imme-
diately, as shown in Table 9.7.
Search WWH ::




Custom Search