Interface Polymorphism
Variables of interface type can hold any object that implements that interface. When calling a method, the actual implementation executed is that of the runtime type, not the declared type. This is the core mechanism of interface polymorphism.
Through interface polymorphism, you can write generic functions and algorithms that don't depend on concrete types, only on the behaviors defined by interfaces. This greatly improves code reusability and extensibility.
Variables of interface type can only access methods declared in the interface at compile time. If you need to access type-specific members, you must use as for type conversion.
In this example, the launch function accepts a Flyable type parameter. When passed a Bird or Airplane, although the declared type is the same, the actual methods called produce different outputs, demonstrating runtime polymorphism.
Add a Drone class that implements Flyable and call launch(Drone("DJI")).