length i elementsimethod1 elementsimethod2

Length i elementsimethod1 elementsimethod2

This preview shows page 3 - 7 out of 11 pages.

for (int i = 0; i < elements.length; i++) { System.out.println(elements[i]); elements[i].method1(); elements[i].method2(); System.out.println(); } } fluteshoe 1flute 2fluteblue 1flute 2moomoo 1moo 2mooblue 1moo 2Use the space below to draw your class hierarchy and method/class output table. 4.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() };
5.What is the difference between overloading and overriding a method?
6.Assume that the following classes have been defined: public class AquaticMammal extends SeaCreature { public void method1() { System.out.println("warm-blooded"); } } public class SeaCreature { public void method1() { System.out.println("creature 1"); } public void method2() { System.out.println("creature2"); } public String toString() { return "ocean-dwelling"; } } public class Whale extends AquaticMammal { public void method1() { System.out.println("spout"); } public String toString() { return "BIG!"; } } public class Squid extends SeaCreature { public void method2() {
System.out.println("tentacles"); } public String toString() { return "squid"; } } (6 cont.) What output is produced by the following code fragment? public static void main (String[] args) { SeaCreature[] elements = { new Squid(), new Whale(), new SeaCreature(), new AquaticMammal() }; for (int i = 0; i < elements.length; i++) { System.out.println(elements[i]); elements[i].method1(); elements[i].method2();
Image of page 7

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture