Source Code:
interface Flyable {
void fly_obj();
}
class Spacecraft implements Flyable {
public void fly_obj() {
System.out.println(“Spacecraft flies in space”);
}
}
class Airplane implements Flyable {
public void fly_obj() {
System.out.println(“Airplane flies in sky”);
}
}
class Helicopter implements Flyable {
public void fly_obj() {
System.out.println(“Helicopter flies low”);
}
}
public class TestFly {
public static void main(String[] args) {
Flyable s = new Spacecraft();
Flyable a = new Airplane();
Flyable h = new Helicopter();
s.fly_obj();
a.fly_obj();
h.fly_obj();
}
}
Output:
