20-CS-122-001 Computer Science II Spring 2012
What's Up With **?

Virtual functions, classes, inheritance, lists, queues, stacks, applications

Prev      Next      Lectures

// Here is how it is done in Java
class A {
   public int number;
   public A (int number) { this.number = number; }
}

public class yikes1 {
   public static void main (String args[]) {
      A a[];   // Acts exactly like "A **a" in C++
      a = new A[10];  // ask for an array of pointers to objects
      for (int i=0 ; i < 10 ; i++) a[i] = new A(i);  // fill the array elems
   
      for (int i=0 ; i < 10 ; i++) System.out.print(a[i].number + " ");
      System.out.println();
   }
}
// Output is "0 1 2 3 4 5 6 7 8 9"