Java Reference
In-Depth Information
13. Assume that the following classes have been defined:
1 public class Bay extends Lake {
2 public void method1() {
3 System.out.print("Bay 1 ");
4 super .method2();
5 }
6 public void method2() {
7 System.out.print("Bay 2 ");
8 }
9 }
1 public class Pond {
2 public void method1() {
3 System.out.print("Pond 1 ");
4 }
5 public void method2() {
6 System.out.print("Pond 2 ");
7 }
8 public void method3() {
9 System.out.print("Pond 3 ");
10 }
11 }
1 public class Ocean extends Bay {
2 public void method2() {
3 System.out.print("Ocean 2 ");
4 }
5 }
1 public class Lake extends Pond {
2 public void method3() {
3 System.out.print("Lake 3 ");
4 method2();
5 }
6 }
What output is produced by the following code fragment?
Pond[] ponds = {new Ocean(), new Pond(), new Lake(), new Bay()};
for (Pond p : ponds) {
p.method1();
System.out.println();
p.method2();
System.out.println();
p.method3();
System.out.println("\n");
}
Search WWH ::




Custom Search