Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
A constructor is a special method in a class that gets called when an object of that class is created. It initializes the object and sets its initial state.
A default constructor is automatically provided by Java if no other constructors are defined in the class. It initializes instance variables with default values (0 for integers, null for objects).
A parameterized constructor allows you to pass arguments at the time of creating an object. It enables you to initialize instance variables with specific values based on those arguments.
Constructor overloading is having multiple constructors within a class with different argument lists. This allows for flexibility in creating objects with various initialization options.