Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to show an example of using Abstract Class and Abstract Method

Posted By: Barney Smith     Category: Java     Views: 3630

A Java Program to show an example of using Abstract Class and Abstract Method.

Code for Program to show an example of using Abstract Class and Abstract Method in Java

 import java.util.Random;

 publicclass JAVA_079
 {

    publicstaticvoid 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( );
       }
    }
 }
  
Share: 



Barney Smith
Barney Smith author of Program to show an example of using Abstract Class and Abstract Method is from Sydney, Australia.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!