• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructor vs setter methods  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

when does one actually need constructors and setter methods at the same time. Are setter methods necessary if i can use a constructor to set my attrbute values ?
Thank you !
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would use constructors to initialize the default value. You would use a setter, typically update the value.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!