• Post Reply Bookmark Topic Watch Topic
  • New Topic

add data to list from abstract class  RSS feed

 
wesley johnsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have 4 classes. The names are: Drawing, DrawingItem (abstract), oval (sub class of drawingitem) and polygon (sub class of drawingitem).
In the class Drawing is a list with name items.
The meaning is that you can add a drawingitem to the list in drawing, for example add the oval to the list.
But you can not do like this: items.add(new DrawingItem(Oval,10, 15 ));
You can no make instance of a abstract class.

my question is: how can I add Drawingitem to the list in class Drawing?

thanks in advance.

my code is:

 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I add Drawingitem to the list in class Drawing? 

Define a class that extends DrawingItem.  Instances of that class can  be added to the list.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using Integers for your numbers rather than ints?
 
Carey Brown
Bartender
Posts: 3009
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest creating an add() method in your Drawing class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!