---
title: "How can I call one constructor from another in Java?"  
description: "How can I call one constructor from another in Java?"  
author: "Utpal Vishwas"  
published: 2023-07-21  
updated: 2023-07-22  
canonical: https://www.mindstick.com/forum/159223/how-can-i-call-one-constructor-from-another-in-java  
category: "java"  
tags: ["java", "class", "constructor"]  
reading_time: 2 minutes  

---

# How can I call one constructor from another in Java?

How can I call [one constructor](https://www.mindstick.com/forum/159570/how-to-call-one-constructor-from-another) from another in [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming)?

## Replies

### Reply by Aryan Kumar

Sure! Here's how you can call one constructor from another in Java:

To call one constructor from another in Java, you can use the `this(...)` keyword. The `this(...)` keyword is used to invoke another constructor in the same class.

The following code shows how to call one constructor from another in Java:

```plaintext
class Person {

  private String name;

  public Person() {
    this("John Doe"); // Calls the constructor with the parameter "John Doe"
  }

  public Person(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }
}

public class Main {

  public static void main(String[] args) {
    Person person = new Person();
    System.out.println(person.getName()); // Prints "John Doe"
  }
}
```

In the code above, the `Person()` constructor calls the `Person(String name)` constructor. The `Person(String name)` constructor initializes the `name` property of the object. The `main()` method creates a new `Person` object and prints the value of the `name` property.

Here are some important things to note about calling one constructor from another in Java:

- The `this(...)` keyword must be the first statement in the constructor that is calling another constructor.
- The constructor that is being called must be in the same class as the constructor that is calling it.
- The parameters of the constructor that is being called must match the parameters of the constructor that is calling it.

Constructor chaining is a powerful technique that can be used to simplify the code for creating objects. It can also be used to avoid duplicate code.


---

Original Source: https://www.mindstick.com/forum/159223/how-can-i-call-one-constructor-from-another-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
