Write a Java program to create an interface Flyable with a method called fly_obj(). Create three classes Spacecraft, Airplane, and Helicopter that implement the Flyable interface. Implement the fly_obj() method for each of the three classes.

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: