---
title: "How many types of constructors are used in Java?"  
description: "How many types of constructors are used in Java?"  
author: "Krishnapriya Rajeev"  
published: 2023-04-29  
updated: 2023-05-01  
canonical: https://www.mindstick.com/forum/158072/how-many-types-of-constructors-are-used-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# How many types of constructors are used in Java?

### How many types of constructors are used in Java?

## Replies

### Reply by Aryan Kumar

There are three types of constructors in Java:

1. **Default constructor:** A constructor that takes no arguments is called a default constructor. If a class does not define any constructors, a default constructor is provided by the compiler. The default constructor initializes all instance variables to their default values (e.g. null for objects, 0 for integers, and false for booleans).
2. **Parameterized constructor:** A constructor that takes one or more arguments is called a parameterized constructor. A parameterized constructor is used to initialize instance variables with values passed as arguments during object creation. Parameterized constructors can also call other constructors using the **this** keyword to reuse code.
3. **Copy constructor:** A constructor that takes an object of the same class as a parameter is called a copy constructor. A copy constructor creates a new object with the same state as the parameter object. This is useful when you want to create a new object that is a copy of an existing object.

Here are examples of each type of constructor:

```java
public class Person {
   private String name;
   private int age;
   // Default constructor
   public Person() {
       name = "";
       age = 0;
   }
   // Parameterized constructor
   public Person(String name, int age) {
       this.name = name;
       this.age = age;
   }
   // Copy constructor
   public Person(Person other) {
       this.name = other.name;
       this.age = other.age;
   }
}
```

### Reply by Krishnapriya Rajeev

Java has the following types of constructors:

1. **Default constructor:** This constructor is provided by Java if there isn't a constructor explicitly defined in a class. It has no parameters and does not perform any sort of initialization. The main purpose of this constructor is to ensure that an object of the class can be created.

2. **Parameterized constructor:** This constructor can be defined with one or more parameters, used to initialize the instance variables of the class. When creating an object using a parameterized constructor, the constructor is called with the specified arguments, and the instance variables are initialized with the values passed as arguments.

3. **Copy constructor:** This constructor is used to create a new object that is a copy of an existing object. However, copy constructors are not provided as default by Java and must be explicitly defined by the programmer.


---

Original Source: https://www.mindstick.com/forum/158072/how-many-types-of-constructors-are-used-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
