Java Constructor Rules

***If this post helped you, please support this blog by clicking one of the links on this page. Thanks :) ***

The following rules must be adhered to when creating Java constructors:

1) The name of the constructor must be the same as the class name for which the constructor is being defined.
2) The constructor must not define a return type.
3) If a constructor is not defined for a class, the compiler creates a default constructor. This default constructor contains no arguments.
4) If a constructor is defined for class, the compiler does not create a default constructor.
5) Overloaded constructors may be created but there cannot be two constructors in the same class with the same argument list.

One Response to “Java Constructor Rules”

  1. What is a Java Constructor? « Joey Javas Says:

    [...] When creating a Java constructor, remember the Java Constructor Rules. [...]

Leave a Reply