Hi All, I just started learning Java and was reading this article on Constructor Overloading. However, I am a bit confused about the rules listed below ->
- The constructor's name should match the name of the class.
- A constructor cannot have a return type.
- A Java constructor cannot use the keywords abstract, static, final, and synchronized.
Are there any other rules I am missing?
Bikash Daga
Level 0
What are the Rules for defining a constructor in Java?
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Ibrahim
14 February 2022, 07:27
Also when overloading constructors the parameters must be different. For example
Above is one constructor, for me to add another one into the same class it must have different parameters so
or
As you can see when overloading, the constructors simply must have different parameters. Don't worry if you feel confused now, just keep reviewing the material and it will start making sense later. 0