• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList is making all objects it Contains the same when a new one is added  RSS feed

 
Carl Ross
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Student And Workshop are both extension classes of Object

The Output Should be:
Lunch
Lunch2

Instead it is
Lunch2
Lunch2

What Have I done Wrong?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carl. I can't see what's wrong, but it's happening inside the CreateWorkShop method. It would be helpful if you posted the code.
 
Carl Ross
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry About That.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A friendly reminder: variables should start with a lower case. This will make life a lot easier for you further down the road.

Anyway, your problem doesn't seem to appear in this method. Maybe the WorkShop.getName() method is broken.

Oh, and welcome to CodeRanch!
 
Carl Ross
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I Thought the same however the getName() is increibly simple:


Hooray!! While uploading this code I found the problem The Declaration of the Name was static.
Thanks for your help
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good job ;)

you should always be careful with the static keyword! Only use it when you really have a good reason to use it.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go back in this forum and Java in General. Have a look for threads about static versus non-static members of classes. There were two about the same time, about three of four weeks ago.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!