Search code examples
java

Can a Java Bean contain one or more parameterized constructors?


I'm new to java and I have a question. According to my knowledge, Java beans have the following properties.

  • They should be serializable, i.e. they should implement the serialization interface.
  • They should have a no-argument constructor.

What is the meaning of have a no-argument constructor? Does it mean that there can only be a no-argument constructor? Can't they have parameterized constructors? Does that mean that bean classes cannot have constructor overloading?


Solution

  • It means that the bean class must have a no-argument constructor. It can have as many constructors as you want, but it must have one no-argument constructor.

    Take into account that any java class without defined constructor will have a default no-argument constructor, but if you add any constructor with arguments, you need to explicitly define a no-argument constructor in this case.