Refresh

This website www.w3schools.blog/does-constructor-return-any-value-in-java is currently offline. Cloudflare's Always Online™ shows a snapshot of this web page from the Internet Archive's Wayback Machine. To check for the live version, click Refresh.

does constructor return any value in java?

Constructor

Constructor is a particular member of the specified class which is used to initialize the state of an object. It gives the values to the data members on the time of object creation that’s the reason it is named constructor.

It does not have any explicit return type but it returns current instance of the specified class.

Example

public class Main
{
    Main(){}
	public static final void main(String[] args) {
	    Main obj1 = new Main();
		System.out.println(obj1 instanceof Main);
	}
}

Output

true

Java interview questions on constructor