Interfaces are sometimes used to indicate which classes have a certain capability or characteristic. Consider the following classes and interfaces. The abstract class Animal has abstract subclasses named Bird and reptile. Classes Dove, eagle Hawk, Penguin and Seagull extend Bird. Classes Rattle Snake and Turtle extend Reptile. The ColdBlooded interface defines no constants and declares no methods. It is implemented by Reptile. The Ocean Dwelling interface also defines no constants and no methods. It is implemented by the Penguin, seagull, and Turtle classes. Define all of these classes and implement the interface as specified. Create one instance of each class. Then display all cold-blooded animals and all ocean-dwelling animals.

source file name: AnimalDemoTest.java

interface ColdBlooded

{

}

interface OceanDwelling

{

}

 abstract class Animal

 {

 abstract public void show ();

 }

class Bird extends Animal

{

public void show()

{

System.out.println ("Bird branch:");

}

}

class Reptile extends Animal implements ColdBlooded

{

public void show()

{

System.out.println ("All Reptile branch is Cold Blooded");

}

}

class Dove extends Bird

{

public void dove()

{

System.out.println ("Dove");

}

}

class Eagle extends Bird implements OceanDwelling

{

public void eagle()

{

System.out.println("Eagle");

}

}

class Penguin extends Bird implements OceanDwelling

{

public void penguin()

{

System.out.println ("Penguin is only OceanDwelling");

}

}

class Seagull extends Bird implements OceanDwelling

{

public void seagull ()

{

System.out.println("Seagull is only OceanDwelling");

}

}

class Hawk extends Bird implements OceanDwelling

{

public void hawk()

{

System.out.println("Hawk");

}

}

class RattleSnake extends Reptile

{

public void rattlesnake() 

{

System.out.println("RattleSnake");

}

}

class Turtle extends Reptile implements OceanDwelling

{

public void turtle()

{

System.out.println ("Turtle is also OceanDwelling");

}

}

class AnimalDemoTest

{

public static void main(String as[])

{

Bird bird = new Bird ();

Reptile reptile = new Reptile() ;

bird.show();

reptile.show();

Dove d = new Dove();

d.dove();

Hawk h = new Hawk();

h.hawk();

Penguin p=new Penguin();

p.penguin();

Eagle e=new Eagle();

e.eagle();

Turtle t=new Turtle();

t.turtle();

RattleSnake rs=new RattleSnake(); 

rs.rattlesnake();

rs.show();

}

}

output:


D:\JavaPrograms\InterfacePrgs>javac AnimalDemoTest.java

D:\JavaPrograms\InterfacePrgs>java AnimalDemoTest
Bird branch:
All Reptile branch is Cold Blooded
Dove
Hawk
Penguin is only OceanDwelling
Eagle
Turtle is also OceanDwelling
RattleSnake
All Reptile branch is Cold Blooded