Advertisement
thenewboston

Java Programming Tutorial - 59 - Class to Hold Objects

Aug 22nd, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. class apples{
  2.    public static void main(String[] args){
  3.      
  4.       DogList DLO = new DogList();
  5.       Dog d = new Dog();
  6.       DLO.add(d);
  7.    }
  8. }
  9.  
  10. public class Fish extends Animal{
  11.  
  12. }
  13.  
  14. public class Dog extends Animal{
  15.  
  16. }
  17.  
  18. public class Animal {
  19.    
  20. }
  21.  
  22. public class DogList {
  23.    private Dog[] thelist = new Dog[5];
  24.    private int i=0;
  25.    
  26.    public void add(Dog d){
  27.       if(i<thelist.length){
  28.          thelist[i]=d;
  29.          System.out.println("Dog added at index "+i);
  30.          i++;
  31.       }
  32.      
  33.    }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement