10 constructor types in Java

Constructors play a key role in all object-oriented programming languages, and Java is no exception.

Every class a Java developer creates needs a constructor. Constructors perform numerous important functions, including the following:

10 types of Java constructors

There is a variety of different types of constructors in Java, and each constructor type has its own special use case and is subject to its own specific set of rules. According to the Java language specification, there are 10 different constructor types in Java:

  1. Default constructor.
  2. Explicit constructors.
  3. Canonical constructors.
  4. Superclass constructors.
  5. Anonymous constructors.
  6. Inner class constructors.
  7. Enum constructors.
  8. Generic constructors.
  9. Private constructors.
  10. Overloaded constructors.

Subtypes of Java constructors

In common parlance, you may also hear developers speak about other types of Java constructors:

  • Copy constructors.
  • Parameterized constructors.
  • No-args constructors.
  • Non-default constructors.

However, technically all of these are subtypes of the 10 Java constructor types listed above.

Cameron McKenzie has been a Java EE software engineer for 20 years. His current specialties include Agile development, DevOps and container-based technologies, such as Docker, Swarm and Kubernetes.

View All Videos