Write a Java application program as required:
(1) define an interface canfly, describe the method that will fly public void Fly ();
(2) define the class airplane and the bird separately, realize the canfly interface.
(3) define a test class, test airplanes and birds, Create aircraft objects and bird objects in the Main method,
Then define a makefly () method, which lets the flying things fly. and Call the method in the main method,
Let the plane and the bird take off.
Public Interface canfly { publicvoid fly ();}
public class Feiji "implements Canfly {@Override public
void Fly () { // TODO auto-generated method stub System.out.println ("Airplane Fly" ); }}
public class niao "implements Canfly {@Override public
void Fly () { // TODO auto-generated method stub System.out.println ("Bird Fly" ); }}
Public class Ceshi { publicvoid makefly (Feiji f,niao N) { f.fly (); N.fly (); } Public Static void Main (string[] args) { Ceshi c=new Ceshi (); Feiji f=new Feiji (); Niao n=new Niao (); C.makefly (f,n); } }
Java Interface Exercises 5