Welcome to Java Examples

Take a cup of tea and Let's Start programming


The Transport interface declares a deliver() method. The abstract class Animal is the super class of
the Tiger, Camel, Deer and Donkey classes.
The Transport interface is implemented by the Camel and Donkey classes. Write a test program that initialize an array of four Animal objects. If the object implements the Transport interface, the deliver() method is invoked.
interface Transport { void deliver(); } abstract class Animal { abstract void disp(); } class Tiger extends Animal { void disp() { System.out.println("Animal --> Tiger\n"); } } class Camel extends Animal implements Transport { void disp() { System.out.println("Animal --> Camel\n"); } Camel() { disp(); deliver(); } public void deliver() { System.out.println("Camel is Delivered...\n"); } } class Deer extends Animal { void disp() { System.out.println("Animal --> Deer\n"); } } class Donkey extends Animal implements Transport { void disp() { System.out.println("Animal --> Donkey \n"); } Donkey() { disp(); deliver(); } public void deliver() { System.out.println("Donkey is on the way...\n"); } } class Animal1 { public static void main(String [] args) { Tiger tig = new Tiger(); Camel cam = new Camel(); Deer dee = new Deer(); Donkey don = new Donkey(); tig.disp(); dee.disp(); } }



output



0 comments :

Post a Comment