Skip to content

Constructors in Java not finished

EWriter edited this page Dec 24, 2021 · 1 revision

It is a special type of method which is used to initialize the object.

Every time an object is created using the new() keyword, at least one constructor is called.

It calls a default constructor if there is no constructor available in the class. In such case, Java compiler provides a default constructor by default.

Constructor name must be the same as its class name
A Constructor must have no explicit return type
A Java constructor cannot be abstract, static, final, and synchronized

Note: We can use access modifiers while declaring a constructor. It controls the object creation. In other words, we can have private, protected, public or default constructor in Java.

There are two types of constructors in Java:

Default constructor (no-arg constructor)
Parameterized constructor

Clone this wiki locally