Java program runtime error
<pre><code>public class Hobbits {
 String name;

 public static void main(String[] args){

  Hobbits [] h = new Hobbits[3];
  int z = 0;

  while (z&lt;4) {
   z = z + 1;
   h[z] = new Hobbits();
   h[z].name = "Bilbo";
   if (z == 1) {
    h[z].name = "Frodo";
   }
   if (z == 2){
    h[z].name = "Sam";
   }
   System.out.print(h[z].name+ " is a ");
   System.out.println("good Hobbit name");

  }
 }
}
</code></pre>

<p>At runtime this program is giving the exception:</p>

<pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
</code></pre>
