Java Reference
In-Depth Information
What is the output produced by the following code fragment?
public static void main(String[] args) {
Moo[] elements = {new Shoe(), new Flute(), new Moo(), new Blue()};
for (int i = 0; i < elements.length; i++) {
System.out.println(elements[i]);
elements[i].method1();
elements[i].method2();
System.out.println();
}
}
10.
Using the classes from the previous problem, write the output that is produced by the following code fragment.
public static void main(String[] args) {
Moo[] elements = {new Blue(), new Moo(), new Shoe(), new Flute()};
for (int i = 0; i < elements.length; i++) {
elements[i].method2();
elements[i].method1();
System.out.println(elements[i]);
System.out.println();
}
}
11.
Assume that the following classes have been defined:
1
public class
Mammal
extends
SeaCreature {
2
public void
method1() {
3 System.out.println("warm-blooded");
4 }
5 }
1
public class
SeaCreature {
2
public void
method1() {
3 System.out.println("creature 1");
4 }
5
6
public void
method2() {
7 System.out.println("creature 2");
8 }
9
10
public
String toString() {
11
return
"ocean-dwelling";
12 }
13 }
Search WWH ::
Custom Search