• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quick ArrayList Question

 
Ben Jass
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, Let's say I have three classes: Polygon, Rectangle, and Oval. Both Oval and Rectangle extend Polygon. So now I'm creating a new ArrayList that I want to hold Polygons and anything that is-a polygon (Rectangle, Oval, etc.).

How can I make an ArrayList take Polygon objects, and any object that is a subclass of Polygon?

Just simply doing this:



Does not work.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34218
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error do you get? The following compiles and runs.

 
Ben Jass
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pointless thread, I guess it works now heh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic