Java Blog

 
 
 
 import java.util.Random;

 public class JAVA_079
 {

    public static void main(String[] args)
    {
       Animal[] theAnimals={ new Dog(\"Rover\",\"Poodle\"),
                             new Cat(\"Max\",\"Abyssinian\"),
                             new Duck(\"Daffy\",\"Aylesbury\"),
                             new Spaniel(\"Fido\")  };

       Animal petChoice;

       Random select=new Random( );

       for(int i=0;i<5;i++)
       {
          petChoice=theAnimals[select.nextInt(theAnimals.length)];

          System.out.println(\"\\nYour Choice :\\n\" + petChoice);

          petChoice.sound( );
       }
    }
 }

 
 
Didn't find what you were looking for? Find more on Program to show an example of using Abstract Class and Abstract Method