Java for Programmers: Lab 11

Create an interface Flyable and 2 classes to implement it, a Seagull and a C130. Create a FlyerLister class to create an Array of Flyables and to iterate through them calling their fly method.

 


package com.annedirkse;


public interface Flyable {

   public void fly();

}

package com.annedirkse; public class C130 implements Flyable { public void fly() {
System.out.println("I am a C130 and I am flying.");
}
}

public class Seagull implements Flyable{ 

  
  public void fly() {
System.out.println("I am a gull, and I am flying."); }

package com.annedirkse; 
  public class FlyerLister {

  
      public static void main(String[] args) {
         Flyable myFlyer = new C130();
myFlyer.fly(); Flyable[] flyers = new Flyable[2];
flyers[0] = new Seagull();
flyers[1] = new C130(); for (int i = 0; i < flyers.length; i++) {
Flyable flyer = flyers[i];
flyer.fly();
} } }