Multiple Interface Implementation in Java


Create a Java program to demonstrate a class implementing multiple interfaces

  • Flyable is an interface that declares a method fly().
  • Swimmable is an interface that declares a method swim().
  • Bird is a class that implements both Flyable and Swimmable interfaces. It provides implementations for both fly() and swim() methods.
  • In the Main class, an instance of Bird is created. It can both fly and swim, so the fly() and swim() methods are called on the bird object, resulting in printing "Bird is Flying" and "Bird is Swimming" to the console, respectively.

Source Code

interface Flyable
{
	void fly();
}
 
interface Swimmable
{
	void swim();
}
 
class Bird implements Flyable, Swimmable
{
	@Override
	public void fly()
	{
		System.out.println("Bird is Flying");
	}
 
	@Override
	public void swim()
	{
		System.out.println("Bird is Swimming");
	}
}
 
public class Main
{
	public static void main(String[] args)
	{
		Bird bird = new Bird();
		bird.fly();
		bird.swim();
	}
}

Output

Bird is Flying
Bird is Swimming

Example Programs