Is it possible to return int/string using constructor in Java?

No. Constructor can’t have any return type. Constructors are used to return the object of the class.

If you see above example. We have created a class Test and in that class we have created a constructor Test that returns nothing. But internally it returns the object of Test.


In above code we have created the object of Test by calling the constructor of Test class.

Be the first to comment

Leave a Reply

Your email address will not be published.