Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dog {
- String name;
- int age;
- String bark(){
- return "This dog barks like this : RUFF RUFF.";
- }
- }//end of class
- public class Kennel{
- public static void main(String[] args){
- //setting up the array mydogs from the Dog Class
- Dog[] mydogs = new Dog[3];
- // setting up the new dog objects to the arrays
- mydogs[0] = new Dog();
- mydogs[1] = new Dog();
- mydogs[2] = new Dog();
- // adding value to the objects created in the array
- // adding info to the first dog
- mydogs[0].name = "ROOFIE";
- mydogs[0].age = 4;
- // adding info to the second dog
- mydogs[1].name = "Spike";
- mydogs[1].age = 7;
- // adding info to the third dog
- mydogs[2].name = "GayLassie";
- mydogs[2].age = 50;
- //calling name and ages of the set up Dogs in the arrays
- //creating a loop to show all the dogs and ages of the dogs!
- int x =0;
- while(x < 3) {
- System.out.println("name =" + " " + mydogs[x].name + " " + "Age =" + " " + mydogs[x].age + " " + mydogs[x].bark());
- x++;
- }//end of while
- }//end of main
- }//end of class
Add Comment
Please, Sign In to add comment