Mixed Array, not a Union

Monkey Forums/Monkey Programming/Mixed Array, not a Union

AdamRedwoods(Posted 2014) [#1]
At first I thought I could create a union type, but now I think that the array just creates pointer space.
In any case, this is one way to get mixed arrays if anyone is interested.

Function Main()
	Local oo:Animal[]= New Animal[10]
	
	oo[0] = New Dog(5)
	oo[1] = New Cat(2,3,4)
	
	Print Dog(oo[0])
	Print Cat(oo[1]) ''union?

	Print oo[0] ''note the odd behavior here for c++ target
	Print oo[1]
End

Interface Animal
	Method ToString$()
end

Class Dog Implements Animal
	Field x:Int
	
	Method New(x:Int)
		Self.x=x
	End
	
	Method ToString$()
		Return x
	End
End

Class Cat  Implements Animal
	Field x:Int, y:Int, z:Int
	
	Method New(x:Int,y:Int,z:Int)
		Self.x=x; Self.y=y; Self.z=z
	End
	
	Method ToString$()
		Return x+" "+y+" "+z
	End
End