Interface creation, implementation, and calls

day_10 Package; 
// Create Interface Port (in press package ALT + Insert, to the class interface)
Port interface {public 
    void Fly (); // default interface method using the modified public abstract 
} 
Package day_10; 

public class Port {Bird the implements 
    @Override 
    public void Fly () {// abstract method of rewriting the interface (ctrl + I) 
        System.out.println ( "bird fly ........"); 
    } 
} 
Package day_10; 

public class Port {Plane the implements 
    @Override 
    public void Fly () { 
        System.out.println ( " aircraft have flight for ...... "); 
    } 
} 
Package day_10; 

public class the Test { 
    public static void main (String [] args) { 
        Port Port; // interface is a reference data type  
        port = new Bird ( ); // Interface implementation class references need to assign objects
        port.fly () ; 
        Port = new new Plane ();
        port.fly();
    }
}

  

Guess you like

Origin www.cnblogs.com/-slz-2/p/11269744.html