Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessor and Mutator in Java Beans

 
Nirav Mehta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I write Bean without having get or set method ? If no whether it will give me run time error or compile time error ???
Pls help me out !!! Thanks....
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you could have a bean without set and get methods. Bean is a Java class and there is no rule about get and set. But if will not have the get and set method than how will you change the bean value? With public fields?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The definition of JavaBean includes getters & setters for variables and a no-parameter constructor. If you leave those things out, it's not a JavaBean. It might still be perfectly useful, but it won't play in frameworks that expect JavaBeans that conform to the definition. Zat help?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic