Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

how to print the attributes of an object



i have a class by the name Veggie which extends Pizza; similarly, i have another subclass: supreme. these are two different types of pizza.

my constructor for Veggie declares an array such that the arguments specified by the constructor take the value of each particular element at the array. for example:

Veggie (String size)
{
String veg [] = new String [1];
veg [0] = size;

}

given the constructors for veggie and supreme, i am allowed to declare a second array of the type Pizza where i can allocate these two different pizzas: Supreme and Veggie. I am also allowed to copy the contents of the Pizza array into a LinkedList.

this is where my question takes place: why is it that when i print the LinkedList: System.out.println(name of linkedlist) i only get:

[Veggie@e90e23, Supreme@9f2588].

I dont want that. I want the out put of my print to be the argument passed to the constructor, which in this case would be "medium" since it specifies the size of my veggie pizza.

how do i make java print not the object's reference, but its attributes which are stored in the form of an array.

any ideas?