---
title: "What is constructor in java?"  
description: "What is constructor in java?"  
author: "Anonymous User"  
published: 2015-03-26  
updated: 2020-09-19  
canonical: https://www.mindstick.com/interview/2360/what-is-constructor-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# What is constructor in java?

Constructor in java is a special type of method that is used to initialize the object.

Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor.

**There are basically two rules defined for the constructor.**

1.Constructor name must be same as its class name

2.Constructor must have no explicit return type

## There are two types of constructors:

1-Default constructor (no-arg constructor)

2-Parameterized constructor

If there is no constructor in a class, compiler automatically creates a default constructor.Default constructor provides the default values to the object like 0, null etc. depending on the type.\

## Answers

### Answer by Anonymous User

Constructor in java is a special type of method that is used to initialize the object.

Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor.

**There are basically two rules defined for the constructor.**

1.Constructor name must be same as its class name

2.Constructor must have no explicit return type

## There are two types of constructors:

1-Default constructor (no-arg constructor)

2-Parameterized constructor

If there is no constructor in a class, compiler automatically creates a default constructor.Default constructor provides the default values to the object like 0, null etc. depending on the type.\


---

Original Source: https://www.mindstick.com/interview/2360/what-is-constructor-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
