Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to show an example of Multiple Levels of Inheritance

Posted By: Rosemary Schmidt     Category: Java     Views: 7429

A Java Program to show an example of Multiple Levels of Inheritance.

Code for Program to show an example of Multiple Levels of Inheritance in Java

 import java.util.Random;

 publicclass JAVA_078
 {

    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: 



Rosemary Schmidt
Rosemary Schmidt author of Program to show an example of Multiple Levels of Inheritance is from Wichita , United States. Rosemary Schmidt says

 
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!