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?
What are the Rules for defining a constructor in Java?
You must be signed in to leave a comment
14 February 2022, 07:27
Also when overloading constructors the parameters must be different. For exampleAbove 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.