ArrayTest2.java Answers

Click here to go back to the questions
// ANSWERS:

// (1) In the doStuff method, define an array of three Human
// objects called threesome.

// HINT: This is almost identical to what you did to create
// the double array in question (2) of ArrayTest.java,
// except that the class Human appears in place of the type
// double.
// 

Human[] threesome = new Human[3];

// 
// (2) Create three new Human objects with names Angus,
// Brian and Charles and assign them to the threesome array.

// HINT: Unlike question (3) of ArrayTest.java, you can't
// use a loop for this.

// 

threesome[0] = new Human("Angus");
threesome[1] = new Human("Brian");
threesome[2] = new Human("Charles");

// 
// (3) In the "doStuff" methodm, add a "for" loop to print
// out the three Human objects using each object's toString
// method.
// 

for (int i=0; i<3; i++) {
   System.out.println(threesome[i].toString());
}

//