Printing address instead of array elements?
<p>So in my code, I made a class named Pet, that would have both a default constructor and a non-default constructor that passes in String name, and int age of the pet. </p>

<pre><code>public class Pet
{
// instance variables 
private int age;
private String name;

/**
 * Constructor for objects of class Pet
 */
    public Pet()
    {
        // initialise instance variables
        age = 0;
        name = "somePet";
    }

    public Pet(int age, String name)
    {
        this.age = age;
        this.name = name; 
    }
}
</code></pre>

<p>Then I created a class named petArray that would add to the array and print out the array...</p>

<pre><code>public class PetArray
{
// instance variables 
private Pet [] petArray;

/**
 * Constructor for objects of class PetArray
 */
public PetArray()
{
    // initialise instance variables
    petArray = new Pet[5];
}

public void addPets()
{
    // put your code here
    Pet myPet = new Pet(4, "Spots");
    petArray[0] = (myPet);
    petArray[1] = new Pet(2, "Lucky");
    petArray[2] = new Pet(7, "Joe");
}

public void printPets()
{
    for (int i = 0; i &lt; petArray.length; i++)
    {
        System.out.println(petArray[i]);
    }
}
</code></pre>

<p>}</p>

<p>But then, I get this in the terminal window when trying to print it out...</p>

<p>Pet@13255e3c
Pet@171ac880
Pet@52185407
null
null</p>