0

I am in an introduction to java programming class and I have a general question about the mutator method in a user-generated class. Can the mutator take in more than one parameter? My textbook so far has only shown examples of mutators with only one parameter, but I have seen mutators with one or more parameters in my homework. Thank you for your help.

Yagiz Degirmenci
  • 16,595
  • 7
  • 65
  • 85
  • 1
    The Java bean _convention_ expects a single parameter. If you're not following the _convention_, you can define your methods with as many parameters as you want. – Savior May 18 '20 at 14:35
  • Thank you for your answer. I would also like to ask about Java bean as I have never heard this term before. – Tuong Trinh May 18 '20 at 14:45
  • 1
    https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly – Savior May 18 '20 at 14:50
  • There are cases where you might want to provide a method that sets two (or more) properties simultaneously, such as a `setSize` method that takes both a _width_ and a _height_. But if you're following the JavaBeans convention, you'd also provide `setWidth` and `setHeight` mutators to set each property individually. – Kevin Anderson May 18 '20 at 14:52

0 Answers0