Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1.  
  2. public class Person {
  3.    
  4.     int num;
  5.  
  6. }
  7.  
  8. class Man {
  9.  
  10.     Person[] p; // creating an array of Person
  11.    
  12.     public Man(int size) {
  13.         p = new Person[size]; // allocating memory the right size for the array
  14.        
  15.         for (int i = 0; i < size; i ++) {
  16.             p[i] = new Person(); // making all the Person's in the array
  17.             p[i].num = i;
  18.         }
  19.     }
  20.    
  21.     public static void main(String[] args) {
  22.        
  23.         Man man = new Man(5);
  24.        
  25.     }
  26.    
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement